...
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=backup DB_PWD=*******backup HOST=host.docker.internal PORT=3355 # cleanup old backups removeOldBackups() { # remove backups older than -mmin for minutes, -mtime for days for i in `ls`find $BACKUP_ARCHIVEDIR/$FILENAME*.tar.gz $BACKUP_ARCHIVEDIR/*.dmp $BACKUP_ARCHIVEDIR/*.err 2>/dev/null -type f -mmin +60 -ls | grep -v $ARCHIVE`o '\S\+$'` 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 --port=$PORT --user=$DB_USER --password= $DB_PWD --log-error=/tmp/$ERRFILE$ER RFILE > /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 rm $BACKUP_ARCHIVEDIR/$ARCHIVE >/dev/null 2>/dev/null exit 1 else rm $BACKUP_WORKDIR/$DMPFILE $BACKUP_WORKDIR/$ERRFILE >/dev/null 2>/dev/null removeOldBackups exit 0 fi |
...
Code Block | ||||
---|---|---|---|---|
| ||||
apiVersion: batch/v1beta1 kind: CronJob metadata: name: batch-every-10-minutes spec: schedule: "*/10 * * * *" concurrencyPolicy: Forbid jobTemplate: spec: template: spec: restartPolicyvolumes: OnFailure - containersname: backup-volume - namepersistentVolumeClaim: mysqldump-backup imageclaimName: ktimoney/mysqldump_backup-claim volumeMountscontainers: - mountPathname: "/tmp"mysqldump-backup image: ktimoney/mysqldump_backup name: backup-volume volumesvolumeMounts: - namemountPath: backup-volume"/tmp" persistentVolumeClaimname: backup-volume restartPolicy: Never claimName backoffLimit: backup-claim3 |
kubectl create -f backupCronjob.yaml
...