Created
August 24, 2012 09:26
-
-
Save e1senh0rn/3448121 to your computer and use it in GitHub Desktop.
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 | |
## Short introduction ## | |
# It is supposed that you have MySQL and lot of files to backup. Done via mk-parallel-dump (maatkit). | |
# Files (as well as DB dumps) are keept versioned, so you can revert to any state during last 20 days. Done via rdiff-backup. | |
# Afterwards, files (with versioning metainfo) are transfered to FTP server. Done via duplicity. | |
# Required software: | |
# 1. maatkit (mk-parallel-dump) | |
# 2. rdiff-backup | |
BACKUPDIR="/backups" | |
SYSBACKUPDIR="${BACKUPDIR}/files" | |
MYSQLUSER="root" | |
MYSQLPASS="pass" | |
MYSQL_OUTDIR="${BACKUPDIR}/mysql" | |
PATH=PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
############ Action definitions ############## | |
backup_dpkg() { | |
dpkg --get-selections > $BACKUPDIR/dpkg-selections.txt | |
} | |
backup_mysql() { | |
rm -rf $MYSQL_OUTDIR | |
if [ ! -d $MYSQL_OUTDIR ]; then | |
mkdir -p $MYSQL_OUTDIR | |
fi | |
#mk-parallel-dump --password ${MYSQLPASS} --user ${MYSQLUSER} --base-dir ${MYSQL_OUTDIR} --nogzip | |
DBS="$(/usr/bin/mysql -u $MYSQLUSER -p$MYSQLPASS -Bse 'show databases')" | |
for db in $DBS | |
do | |
### Create dir for each databases, backup tables in individual files ### | |
mkdir $MYSQL_OUTDIR/$db | |
for i in `/usr/bin/mysql -u $MYSQLUSER -p$MYSQLPASS $db -Bse 'show tables'` | |
do | |
FILE=$MYSQL_OUTDIR/$db/$i.sql | |
/usr/bin/mysqldump --add-drop-table --allow-keywords -q -c -u $MYSQLUSER -p$MYSQLPASS $db $i > $FILE | |
done | |
done | |
find ${MYSQL_OUTDIR} -type f -name '*.sql' -exec gzip --best -f '{}' \; | |
} | |
backup_files() { | |
#cleanup | |
rdiff-backup --force --remove-older-than 20D $SYSBACKUPDIR 2>/dev/null | |
#do backup | |
rdiff-backup \ | |
--exclude $SYSBACKUPDIR \ | |
--exclude '/home/*/dl' \ | |
--exclude '/home/*/tmp' \ | |
--exclude '**.log' \ | |
--exclude '**.log.1' \ | |
--exclude '**.log.*.gz' \ | |
--exclude /var/www/web_daemons/www/noc.daemons.org.ua/public_html/munin \ | |
--include /var/spool/cron/crontabs \ | |
--include /var/backups \ | |
--include /etc \ | |
--include /root \ | |
--include /var/www \ | |
--exclude /var/www/*/chroot \ | |
--include /var/lib/awstats \ | |
--include /home \ | |
--include /usr/local \ | |
--include /var/lib/dpkg/status \ | |
--include /var/lib/dpkg/status-old \ | |
--include ${MYSQL_OUTDIR} \ | |
--exclude '/*' \ | |
/ $SYSBACKUPDIR | |
} | |
########## Action sequence ######## | |
backup_dpkg | |
backup_mysql | |
backup_files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment