Last active
February 3, 2016 04:59
-
-
Save techjanitor/c14743d065b5c484a825 to your computer and use it in GitHub Desktop.
mysql backup cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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