...
The backups will be stored remotely.
The example below works on windows 10 running docker desktop with kubernetes enabled.
mariadb is installed on ubuntu using port 3355 instead of the default.
/etc/mysql/my.cnf
[mysqld]
port=3355
Dockerfile
Code Block | ||||
---|---|---|---|---|
| ||||
FROM mariadb:latest RUN apt update COPY mysqldump_backup.sh . ENTRYPOINT [ "/bin/sh" ] CMD [ "./mysqldump_backup.sh" ] |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#!/bin/sh FILENAME=$(basename $0 .sh) BACKUP_TS=$(date +%F-%T) ARCHIVE=${FILENAME}_${BACKUP_TS}.tar.gz ERRFILE=${FILENAME}_${BACKUP_TS}.err DMPFILE=${FILENAME}_${BACKUP_TS}.dmp LOG_DIR=/tmp BACKUP_WORKDIR=/tmp BACKUP_ARCHIVEDIR=/tmp MARIADB_BACKUP_EXE_DIR="/usr/bin" DB_USER=policy DB_PWD=******* HOST=host.docker.internal PORT=3355 # cleanup old backups removeOldBackups() { for i in `ls $BACKUP_ARCHIVEDIR/$FILENAME*.tar.gz | grep -v $ARCHIVE` do rm $i >/dev/null 2>/dev/null done } cd / echo "Backup Started" # call backup utility { "$MARIADB_BACKUP_EXE_DIR"/mysqldump --all-databases --host=$HOST --user=$DB_USER --password= $DB_PWD --log-error=/tmp/$ERRFILE > /tmp/$DMPFILE } echo >&2 "Backup Complete" # create a tar archive from the backup directory tar cvzf $BACKUP_ARCHIVEDIR/$ARCHIVE $BACKUP_WORKDIR/$DMPFILE $BACKUP_WORKDIR/$ERRFILE >/dev/null 2>/dev/null # check for errors if [ -s "$BACKUP_WORKDIR/$ERRFILE" ] then exit 1 else rm $BACKUP_WORKDIR/$DMPFILE $BACKUP_WORKDIR/$ERRFILE removeOldBackups exit 0 fi |
...
docker build . -t ktimoney/mysqldump_backup
...