Skip to content

Instantly share code, notes, and snippets.

@initcron
Created August 29, 2012 05:23
Show Gist options
  • Save initcron/3507089 to your computer and use it in GitHub Desktop.
Save initcron/3507089 to your computer and use it in GitHub Desktop.
/root/xtra_mysqlbackup.sh
#!/bin/bash
BACKUP_DIR=/backups
PASS="randompasswordhere"
MYSQL_CONFIG=/etc/mysql/my.cnf
echo "Creating Backup..."
innobackupex --defaults-file=$MYSQL_CONFIG --password=$PASS $BACKUP_DIR/
echo "DONE Creating Backup!"
NEWPATH=`ls -tr /$BACKUP_DIR/ | tail -n 1`
echo "Preparing Backup..."
innobackupex --defaults-file=$MYSQL_CONFIG --password=$PASS --apply-log /$BACKUP_DIR/$NEWPATH
echo "Done Preparing Backup!"
echo "Cleaning up backups older than 7 days..."
cd $BACKUP_DIR && find /$BACKUP_DIR/ -type d -mtime +7 -exec rm -rf '{}' \;
echo "ALL DONE!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment