Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titledb_backup.sh
#!/bin/sh

LOG=$(basename $0 .sh)_$(date +%F-%T).log
LOG_DIR=/c/mariadb/logs
BACKUP_DIR1=/c/mariadb/backup1
BACKUP_DIR2=/c/mariadb/backup2
MARIADB_BACKUP_EXE_DIR="/C/Program Files/MariaDB 10.5/bin"
USER=policyp#####
PWD=P01icY******
OK_MSG="completed OK!"

# if the backup directory doesn't exist, create it
if [ ! -d $BACKUP_DIR1 ]; then
        mkdir -p $BACKUP_DIR1
fi

# if the backup directory doesn't exist, create it
if [ ! -d $BACKUP_DIR2 ]; then
        mkdir -p $BACKUP_DIR2
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_DIR"

# check if directory is empty, if not delete it's contents
if [ "$(ls -A $BACKUP_DIR)" ]; then
     rm -rf $BACKUP_DIR/*
fi

# redirect output to log file
{
"$MARIADB_BACKUP_EXE_DIR"/mariabackup --backup --target-dir=$BACKUP_DIR --user=$USER --password=$PWD
} >$LOG_DIR/$LOG 2>&1
echo >&2 "Backup Complete"

# 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

...