Skip to content

Instantly share code, notes, and snippets.

@darookee
Created January 21, 2016 21:10
Show Gist options
  • Select an option

  • Save darookee/3fb99f2e1da439cf1948 to your computer and use it in GitHub Desktop.

Select an option

Save darookee/3fb99f2e1da439cf1948 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Requires zbackup
# zbackup-backups will not be encrypted (no password file)
# uses lftp to upload $BACKUPDIR contents to remote ftp
BACKUPDIR="/var/backups/"
FTPUSER=""
FTPPASS=""
FTPHOST=""
MYUSER=""
MYPASS=""
MYHOST=""
source ~/.backup.conf
backup_mail() {
# MAILBACKUP
MAILSNAPSHOTNAME="mail_snapshot"
MAILSOURCEGROUP="/dev/vg0/mail"
MAILBKTMPDIR="/var/tmp/backup/mail"
BACKUPDIR="/var/backups/"
echo "Creating snapshot..."
/sbin/lvcreate -L5G -s -n ${MAILSNAPSHOTNAME} ${MAILSOURCEGROUP}
echo "Mounting snapshot..."
/bin/mount /dev/vg0/${MAILSNAPSHOTNAME} ${MAILBKTMPDIR}
echo "Backing up mails... (${BACKUPDIR}/backups/)"
cd ${MAILBACKUPDIR}
/bin/tar -c ${MAILBKTMPDIR} | /usr/local/bin/zbackup backup ${BACKUPDIR}/backups/mails-`date +"%Y%m%d_%H%M%S"`
echo "Unmounting..."
/bin/umount ${MAILBKTMPDIR}
echo "Removing snapshot..."
/sbin/lvremove -f /dev/vg0/${MAILSNAPSHOTNAME}
echo "done"
}
backup_www() {
WWWSNAPSHOTNAME="www_snapshot"
WWWSOURCEGROUP="/dev/vg0/www"
WWWBKTMPDIR="/var/tmp/backup/www"
BACKUPDIR="/var/backups/"
echo "Creating snapshot..."
/sbin/lvcreate -L5G -s -n ${WWWSNAPSHOTNAME} ${WWWSOURCEGROUP}
echo "Mounting snapshot..."
/bin/mount /dev/vg0/${WWWSNAPSHOTNAME} ${WWWBKTMPDIR}
echo "Backing up wwws... (${BACKUPDIR}/backups/)"
cd ${WWWBACKUPDIR}
/bin/tar -c ${WWWBKTMPDIR} | /usr/local/bin/zbackup backup ${BACKUPDIR}/backups/www-`date +"%Y%m%d_%H%M%S"`
echo "Unmounting..."
/bin/umount ${WWWBKTMPDIR}
echo "Removing snapshot..."
/sbin/lvremove -f /dev/vg0/${WWWSNAPSHOTNAME}
echo "done"
}
backup_mysql() {
# MySQL Backup
PREDATE=`date --date="7 days ago" +"%Y-%m-%d %H:%M:%S"`
echo "PURGE BINARY LOGS BEFORE '${PREDATE}';"|mysql -u ${MYUSER} -h ${MYHOST} -p${MYPASS}
/usr/bin/mylvmbackup
}
backup_gitlab() {
OLDPATH=`pwd`
cd ~git/gitlab
find /home/git/gitlab/tmp/backups -mtime +7 -exec rm {} \;
# GITLAB BACKUP
BKPFILE=`RAILS_ENV=production su -c "~git/.rvm/bin/gitlab_bundle exec rake gitlab:backup:create" git|grep Creating|awk -F\: '{ print $2 }'|awk '{ print $1 }'`
cat ~git/gitlab/tmp/backups/${BKPFILE} | /usr/local/bin/zbackup backup /var/backups/backups/gitlab-`date '+%Y-%m-%d%H%M%S'`
cd $OLDPATH
}
backup_transfer() {
# TRANSFER BACKUP
/usr/bin/lftp -e 'set net:timeout 10; mirror -eR /var/backups /; bye' -u ${FTPUSER},${FTPPASS} ${FTPHOST}
}
backup_all() {
backup_mail
backup_www
backup_mysql
backup_gitlab
backup_transfer
/bin/du -sh ${BACKUPDIR}
}
if [ "${1}" == "" ]; then
backup_all
else
backup_${1}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment