MySQL

From HyperSecurity Wiki
Jump to: navigation, search
#!/bin/sh
#Written by Shawn Rapaz on May 13th, 2013
#This script backups up the complete MySQL database nightly.
curDate="/bin/date +%Y-%m-%d"
DATESTAMP=`/bin/date "+%Y-%m-%d"`
BACKUP_DIR="/root/backups/database_dumps/"
echo "Starting hourly backup of MySQL database (full)..."
#Does the pgsql dump and compresses it with bzip2
mysqldump --all-databases -u root -pPASSWORD > /tmp/alldatabases_nightly.sql
/bin/mv /tmp/alldatabases_nightly.sql /tmp/alldatabases_nightly-$DATESTAMP.sql
/usr/bin/bzip2 /tmp/alldatabases_nightly-*.sql
#This moves the hourly backup to /space/backups/pgsql/hourly on db.accel
/bin/mv -f /tmp/alldatabases_nightly-*.sql.bz2 $BACKUP_DIR
echo "Postgresql hourly backup completed."
# look for files in archive directory and remove any that are older than 3*24hrs from current date of script starting
echo "Removing files older than 3 days"
find $BACKUP_DIR -type f -mtime +3 -exec rm {} \;
echo "MySql nightly dump completed at $DATESTAMP"
exit 0