Skip to content

Instantly share code, notes, and snippets.

@e1senh0rn
Created May 11, 2009 22:18
Show Gist options
  • Save e1senh0rn/110216 to your computer and use it in GitHub Desktop.
Save e1senh0rn/110216 to your computer and use it in GitHub Desktop.
#!/bin/bash
## Short introduction ##
# It is supposed that you have MySQL to backup. Done via mk-parallel-dump (maatkit).
# Files (including DB dumps) are keept versioned, so you can revert to any state during last 20 days. Done via rdiff-backup.
# Afterwards, files (with versions metainfo) are transfered to FTP server. Done via duplicity.
# Required software:
# 1. maatkit (mk-parallel-dump)
# 2. rdiff-backup
# 3. duplicity (it requires ncftp to store backup on ftp host)
BACKUPDIR="/home/backups"
SYSBACKUPDIR="${BACKUPDIR}/files"
MYSQLUSER="root"
MYSQLPASS="mysql_root_password_here"
MYSQL_OUTDIR="${BACKUPDIR}/mysql"
FTP_USER="backup"
FTP_PASSWORD='keep-it-safe'
FTP_HOST="backup.dc.somewhere.com"
FTP_PATH="files"
PATH=PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
############ Action definitions ##############
backup_dpkg() {
dpkg --get-selections > $BACKUPDIR/dpkg-selections.txt
}
backup_mysql() {
if [ ! -d $MYSQL_OUTDIR ]; then
mkdir -p $MYSQL_OUTDIR
fi
rm $MYSQL_OUTDIR/* 2>/dev/null
mk-parallel-dump --password ${MYSQLPASS} --user ${MYSQLUSER} --basedir ${MYSQL_OUTDIR} --no-gzip
find ${MYSQL_OUTDIR} -type f -name *.sql -exec gzip --best -f '{}' \;
}
backup_files() {
#cleanup
rdiff-backup --remove-older-than 20D $SYSBACKUPDIR 2>/dev/null
#do backup
rdiff-backup --exclude $SYSBACKUPDIR \
--exclude '/home/*/dl' \
--exclude '/home/*/tmp' \
--exclude '**.log' \
--include /var/spool/cron/crontabs \
--include /var/backups \
--include /etc \
--include /root \
--include /var/www \
--include /home \
--include /usr/local \
--include /var/lib/dpkg/status \
--include /var/lib/dpkg/status-old \
--exclude '/*' \
/ $SYSBACKUPDIR
}
backup_to_ftp() {
export FTP_PASSWORD
duplicity remove-older-than 1D --no-encryption ftp://${FTP_USER}@${FTP_HOST}/${FTP_PATH}
duplicity remove-all-but-n-full 1 --no-encryption ftp://${FTP_USER}@${FTP_HOST}/${FTP_PATH}
duplicity --no-encryption --volsize=100 $SYSBACKUPDIR ftp://${FTP_USER}@${FTP_HOST}/${FTP_PATH}
unset FTP_PASSWORD
}
########## Action sequence ########
backup_dpkg
backup_mysql
backup_files
backup_to_ftp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment