Add initial backup service with Docker and scripts
This commit introduces a Dockerized backup service, including a Dockerfile, a placeholder `backup.sh` script, and a functional `database_export.sh` script for creating database backups. The setup ensures required validations and dependencies for safely exporting database content. Further implementation is needed in `backup.sh`.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
FROM ubuntu:latest
|
||||
LABEL authors="Jeppe B"
|
||||
RUN apt-get update && apt-get install -y cron
|
||||
COPY backup.sh /backup.sh
|
||||
RUN chmod +x /backup.sh
|
||||
# Set the timezone
|
||||
RUN ln -fs /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime
|
||||
# Send a message, and run the backup script
|
||||
CMD echo "Backup service is running" && /backup.sh
|
||||
@@ -0,0 +1,3 @@
|
||||
# Show the script is running
|
||||
echo "Backup script started at $(date)"
|
||||
# TODO: Implement the script here
|
||||
@@ -0,0 +1,74 @@
|
||||
# Create a database backup
|
||||
# Usage: backup.sh <host> <port> <database> <backup_dir> <backup_file> <user> <password>
|
||||
|
||||
# Check if the host is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo "Host is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the port is provided
|
||||
if [ -z "$2" ]; then
|
||||
echo "Port is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the database is provided
|
||||
if [ -z "$3" ]; then
|
||||
echo "Database is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the backup directory is provided
|
||||
if [ -z "$4" ]; then
|
||||
echo "Backup directory is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the backup file is provided
|
||||
if [ -z "$5" ]; then
|
||||
echo "Backup file is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the user is provided
|
||||
if [ -z "$6" ]; then
|
||||
echo "User is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the password is provided
|
||||
if [ -z "$7" ]; then
|
||||
echo "Password is not provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the backup directory exists
|
||||
if [ ! -d "$4" ]; then
|
||||
echo "Backup directory $4 does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the backup file exists
|
||||
if [ -f "$4"/"$5" ]; then
|
||||
echo "Backup file $4/$5 already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the database exists
|
||||
if ! mysql --host "$1" -P "$2" -u "$6" -p "$7" -e "use $3"; then
|
||||
echo "Database $3 does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a backup file
|
||||
mysqldump --host "$1" -P "$2" -u "$6" -p "$7" "$3" > "$4"/"$5"
|
||||
|
||||
# Check if the backup file is created
|
||||
if [ ! -f "$4"/"$5" ]; then
|
||||
echo "Backup file is not created"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Print the backup file path
|
||||
echo "Backup file is created: $4/$5"
|
||||
Reference in New Issue
Block a user