#!/bin/sh
# You'll need to change anything munged, localuser to be a local user on your machine, 
# localmachine to your host name (optional), admin.server.com to your own backup server, 
# and probably the SSH port (not required at all if you're running SSH on port 22). These 
# scripts log all their actions as well as report the available disk space at the end of 
# the backups and emails the reports to me locally just for good measure. I don't always 
# notice if a backup report isn't present, but I have become accustomed to getting the 
# daily backup emails and I notice if they're missing. The incremental also includes 
# collection status reports in the report.

# Export the PASSPHRASE variable
export PASSPHRASE=munged

# Get the date
repDate=`date +%Y%m%d`;

# Cleanup first (anything older than 21 days)
/usr/bin/duplicity remove-older-than 14D -v9 --force scp://root@admin.server.com:2035//backup/localmachine

# Now do the backup
/usr/bin/duplicity --include /home/localuser/Documents --include /home/localuser/.mozilla-thunderbird/01pvkqct.default/ImapMail/mail.messagingengine.com --include /home/localuser/scripts --exclude '**' /home/localuser/ scp://root@admin.server.com:2035//backup/localmachine --sign-key MUNGED > /home/localuser/Documents/BackupLogs/Incremental_Backup_Log_${repDate}_localmachine_admin.log

# Get list of backups
/usr/bin/duplicity collection-status scp://root@admin.server.com:2035//backup/localmachine >> /home/localuser/Documents/BackupLogs/Incremental_Backup_Log_${repDate}_localmachine_admin.log

# Get the disk space
echo "\nAvailble Disk Space on Server" >> /home/localuser/Documents/BackupLogs/Incremental_Backup_Log_${repDate}_localmachine_admin.log
echo >> /home/localuser/Documents/BackupLogs/Incremental_Backup_Log_${repDate}_localmachine_admin.log
/usr/bin/ssh -p2035 root@admin.server.com df -h >> /home/localuser/Documents/BackupLogs/Incremental_Backup_Log_${repDate}_localmachine_admin.log

# Mail me the results
mail -t localuser -s "localmachine Backup Incremental (Admin)" < /home/localuser/Documents/BackupLogs/Incremental_Backup_Log_${repDate}_localmachine_admin.log