Skip to content

Instantly share code, notes, and snippets.

@techjanitor
Last active February 3, 2016 04:59
Show Gist options
  • Save techjanitor/c14743d065b5c484a825 to your computer and use it in GitHub Desktop.
Save techjanitor/c14743d065b5c484a825 to your computer and use it in GitHub Desktop.
mysql backup cron
#!/bin/bash
# creates a mysql backup
#
# CREATE USER 'backups'@'localhost' IDENTIFIED BY 'password';
# GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'backups'@'localhost';
# FLUSH PRIVILEGES;
#
# restore: innobackupex --copy-back /data/backups/whatever
# timestamp
DATE=$(date +"%Y%m%d")
# directory
DIR="/data/backups/$DATE"
# archive name
TAR="/data/backups/backup-$DATE.tar.gz"
set -eu
innobackupex --user=backups --password=password --no-timestamp $DIR
innobackupex --apply-log /data/backups/$DATE
nice -n 10 tar -cvzf $TAR $DIR
rm -rf $DIR
find /data/backups -mtime +7 -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment