Skip to content

Instantly share code, notes, and snippets.

@tcz
Created February 5, 2012 15:50
Show Gist options
  • Save tcz/1746180 to your computer and use it in GitHub Desktop.
Save tcz/1746180 to your computer and use it in GitHub Desktop.
MySQL backup with innobackupex and s3cmd
#!/bin/bash
INNOBACKUP="/root/percona-xtrabackup/innobackupex"
INNOBACKUP_OPTIONS="--defaults-file=/etc/my.cnf --ibbackup=/root/percona-xtrabackup/mysql-5.5/storage/innobase/xtrabackup/xtrabackup_innodb55 --parallel=4 --user=root --password=XXXXXXX"
BACKUPDIR="/var/sqlbackup/"
S3BUCKET="db_backup"
echo "Removing old local backups"
cd $BACKUPDIR
find . -type d -name "." -prune -o -type d -atime +3 -exec rm -rf {} \; -print
echo "Starting INNODBACKUP:"
echo "$INNOBACKUP $INNOBACKUP_OPTIONS $BACKUPDIR"
$INNOBACKUP $INNOBACKUP_OPTIONS $BACKUPDIR
echo "Sleeping for a 1 min 10 seconds"
sleep 70
S3_DIR_UPLOAD=`find . -maxdepth 1 -type d -cmin +1 -print |grep ./ |cut -d. -f2 |cut -d/ -f2|xargs`
echo "Dir to Synchronize are $S3_DIR_UPLOAD"
for dir in $S3_DIR_UPLOAD; do
echo "Uploading $dir"
s3cmd put --recursive $dir s3://$S3BUCKET/
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment