Skip to content

Instantly share code, notes, and snippets.

@rakeshr
Forked from Silvenga/dup-backup.sh
Created March 14, 2014 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rakeshr/9548039 to your computer and use it in GitHub Desktop.
Save rakeshr/9548039 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Place in /usr/share/backup/
# and make executable
# chmod 0744 dup-backup.sh
# install:
# apt-get install duplicity python-gdata python-gobject-2 python-paramiko
## Remeber to change Google drive user name and Google drive folder
## And change Email
# Must run as root for system wide backups
# su -u root
# For cron job:
#su -l root # login to root to edit root's cron jobs
#crontab -e
#0 1 * * * /usr/share/backup/dup-backup.sh # will run at 00:00 every day
# GPG Password
# Use for encrypting all data on remote storing host
# No spaces
export PASSPHRASE=very hard password
# GDrive Password
# Password for logging into Google drive
# No spaces
export FTP_PASSWORD=password
echo "Started At: `date`." >>/var/log/duplicity/backup.log
echo "Starting Backup." >>/var/log/duplicity/backup.log
echo "" >>/var/log/duplicity/backup.log
# Make exceptions to back up. Add anything you want.
# Made with the assumptions that we care about only the data
# that we can restore on any machine running the current OS
#
# "- /file/path"
# Add more if errors out
cat > /usr/share/backup/filelist.txt <<EOF
- /dev
- /proc
- /lost+found
- /media
- /mnt
- /run
- /tmp
- /boot
- /selinux
- /root/.cache
- /sys
EOF
# Loading the day of the month
date=`date +%d`
# Check to see if we're at the first of the month.
# If so then run a full backup.
# If not, then run an incremental backup
# duplicity with blank options will run incremental, if fails, then run full
# using duplicity full to force full backup
if [ $date = 01 ]
then
echo "Doing Full Backup..." >>/var/log/duplicity/backup.log
duplicity full --exclude-filelist /usr/share/backup/filelist.txt / gdocs://username/folder >>/var/log/duplicity/backup.log
else
echo "Doing Incremental Backup..." >>/var/log/duplicity/backup.log
duplicity --exclude-filelist /usr/share/backup/filelist.txt / gdocs://username/folder >>/var/log/duplicity/backup.log
fi
echo "Done." >>/var/log/duplicity/backup.log
echo "" >>/var/log/duplicity/backup.log
# Delete old backups
# One full backup each month means will remove backups
# older than 3 months
echo "Cleaning Backups..." >>/var/log/duplicity/backup.log
duplicity remove-all-but-n-full 3 --force gdocs://m@silvenga.com/vpn01 >>/var/log/duplicity/backup.log
echo "Done." >>/var/log/duplicity/backup.log
echo "" >>/var/log/duplicity/backup.log
# Destroying passwords saved to memory
unset PASSPHRASE
unset FTP_PASSWORD
# Email log
echo "Backup Finished, Emailing Log..." >>/var/log/duplicity/backup.log
# If you want beautiful HTML emails, requires ansifilter found on sourceforge
#ansifilter -i /var/log/duplicity/backup.log -o /var/log/duplicity/backup.log.html -H
#mail -a 'Content-Type: text/html' -s 'Daily Backup Report' admin@silvenga.com </var/log/duplicity/backup.log.html
#rm /var/log/duplicity/backup.log.html
mail -s 'Daily Backup Report' root@localhost </var/log/duplicity/backup.log
# Remove old backup log, and backup current log
rm /var/log/duplicity/backup.log.bak
mv /var/log/duplicity/backup.log /var/log/duplicity/backup.log.bak
# Done!
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment