Created
January 9, 2013 11:21
-
-
Save BenAtWide/4492411 to your computer and use it in GitHub Desktop.
Encrypted rotated backups of MySQL databases, from Jon Allie http://jonallie.com/blog/post/65/
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 | |
# setup | |
suffix=`date +%Y%m%d` | |
dest=/home/wide/dbs | |
cmd='/usr/bin/mysqldump' | |
user='backuper' | |
password='jfhiue839' | |
#databases="mysql test" | |
databases='fuk_production mysql' | |
#echo "Backing up databases... $databases" | |
for d in $databases; do | |
s="use ${d}; show tables;" | |
tables=(`echo ${s} | /usr/bin/mysql -u ${user} --password=${password} | grep -v '^Tables_in_'`) | |
for t in "${tables[@]}"; do | |
if [[ $t != 'events' && $t != 'general_log' && $t != 'slow_log' ]] | |
then | |
path="${dest}/${suffix}/${d}" | |
mkdir -p ${path} | |
${cmd} -u ${user} --password=${password} --quick --add-drop-table --create-options ${d} ${t} | bzip2 -c > ${path}/${t}.sql.bz2 | |
fi | |
done | |
done | |
# delete old dumps (retain 5 days) | |
find ${dest} -maxdepth 1 -mtime +5 -exec rm -rf {} \; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment