mysql-backup-agent/backup.sh

28 lines
853 B
Bash

#!/bin/bash
echo "Beginning Hot-Backup of database..." >> /var/log/cron.log
# Check if MYSQL_HOST is defined
if [ -z "$MYSQL_HOST" ]; then
echo "Error: MYSQL_HOST is not defined." >> /var/log/cron.log
exit 1
fi
# Check if MYSQL_ROOT_PASS is defined
if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
echo "Error: MYSQL_ROOT_PASS is not defined." >> /var/log/cron.log
exit 1
fi
# Check if BACKUP_NAME is defined
if [ -z "$BACKUP_NAME" ]; then
export BACKUP_NAME=$MYSQL_HOST
fi
#Figure out what to name the out file
if $APPEND_DATE; then
current_date=$(date +"%Y-%m-%d")
FILENAME="$BACKUP_NAME($current_date).sql"
else
FILENAME="$BACKUP_NAME.sql"
fi
mysqldump -u root --password=$MYSQL_ROOT_PASSWORD --host=$MYSQL_HOST --all-databases --log-error=/var/log/cron.log> "/backup/$FILENAME"
echo "MySQL backup complete" >> /var/log/cron.log