...
Code Block | ||||
---|---|---|---|---|
| ||||
#!/bin/sh LOGFILENAME=$(basename $0 .sh)_$(date +%F-%T) ARCHIVE=${FILENAME}.tar.gz LOG=${FILENAME}.log LOG_DIR=/c/mariadb/logs BACKUP_DIR1WORKDIR=/c/mariadb/backup1backup BACKUP_DIR2ARCHIVEDIR=/c/mariadb/backup2backup_archives MARIADB_BACKUP_EXE_DIR="/C/Program Files/MariaDB 10.5/bin" USER=p#####policy PWD=******P01icY OK_MSG="completed OK!" # if the backup directory doesn't exist, create it if [ ! -d $BACKUP_DIR1WORKDIR ]; then mkdir -p $BACKUP_DIR1WORKDIR fi # if the backuparchive directory doesn't exist, create it if [ ! -d $BACKUP_DIR2ARCHIVEDIR ]; then mkdir -p $BACKUP_DIR2ARCHIVEDIR fi # Find the backup directory with the oldest modification date BACKUP_DIR=`ls -td $BACKUP_DIR1/ $BACKUP_DIR2/ | tail -1 | awk -F' ' '{print $NF}' | sed 's/.$//'` # if the log directory doesn't exist, create it if [ ! -d $LOG_DIR ]; then mkdir -p $LOG_DIR fi echo "Backup Started" echo "Backing up to $BACKUP_DIRWORKDIR" # check if directory is empty, if not delete it's contents if [ "$(ls -A $BACKUP_DIRWORKDIR)" ]; then rm -rf $BACKUP_DIRWORKDIR/* fi # redirect output to log file { "$MARIADB_BACKUP_EXE_DIR"/mariabackup --backup --target-dir=$BACKUP_DIRWORKDIR --user=$USER --password=$PWD } >$LOG_DIR/$LOG 2>&1 echo >&2 "Backup Complete" # create a tar archive from the backup directory tar cvzf $BACKUP_ARCHIVEDIR/$ARCHIVE $BACKUP_WORKDIR >/dev/null 2>/dev/null # remove he bckup directory rm -rf $BACKUP_WORKDIR >/dev/null 2>/dev/null # check the log for the "completed OK!" message grep -q "$OK_MSG" $LOG_DIR/$LOG if [ $? -eq 0 ]; then exit 0 else exit 1 fi |
...