#!/bin/bash backuplog="/var/log/backup.log" echo "" >> "${backuplog}" START_BACKUP_DATE=$(date +%Y.%m.%d.%H.%M) DATE=$(date +%Y.%m.%d) echo "Start Backup: $START_BACKUP_DATE" >> "${backuplog}" error_out () { echo "ERROR: Could not back up: $1" >> "${backuplog}" echo "" >> "${backuplog}" exit 1 } echo "starting music backup" >> "${backuplog}" /usr/local/bin/sync.music.sh echo "done with music backup" >> "${backuplog}" echo "Mounting drive" >> "${backuplog}" echo "" echo "unlock backup drive:" while true do geli attach /dev/da0 if [ $? -eq 0 ]; then break fi done mount /dev/da0.eli /mnt/backup >> "${backuplog}" if [ ! $? -eq 0 ] then echo "could not mount external drive" | mail -s "backup error" "backups@alerthost.com" fi echo "Drive Mounted" >> "${backuplog}" echo "######## Starting Backup" >> "${backuplog}" echo "#### Getting the latest Oh-Shit-File" >> "${backuplog}" curl --header 'Host: somehost.notforyou.com' --header 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0' --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' --header 'Accept-Language: en-US,en;q=0.5' --header 'DNT: 1' --header 'Content-Type: application/x-www-form-urlencoded' --header 'Cookie: rsakey=sb23d3522l4ea9b5f27; Wiki=l214l2lkjfq5jcql4to45bs2b27' 'https://somehost.notforyou.com/oh_shit_file' -O -J -L if [ ! $? -eq 0 ] then echo "could not get oh-shit file" | mail -s "backup error" "backups@alerthost.com" fi echo "#### Oh-Shit-File downloaded" >> "${backuplog}" echo "#### Mail Backup" >> "${backuplog}" read -s -p "Press enter then unlock key: " rsync -e "ssh -i ${ssh_key_file}" --no-motd --size-only --log-file="${backuplog}" -rlDvz user@somehost.notforyou.com:mail /home/user/ >> "${backuplog}" if [ ! $? -eq 0 ] then echo "could not sync from somehost.notforyou.com" | mail -s "backup error" "backups@alerthost.com" fi cp -r /home/user/mail /mnt/backups/mail/somehost.notforyou.com/ >> "${backuplog}" if [ ! $? -eq 0 ] then echo "could not move somehost.notforyou.com files to backup" | mail -s "backup error" "backups@alerthost.com" fi read -s -p "Press enter then unlock key 2x: " rsync -e "ssh -i ${ssh_key_file}" --no-motd --size-only --log-file="${backuplog}" -rlDvz /home/user/mail user@store.notforyou.com:/data/backups/mail/somehost.notforyou.com/ >> "${backuplog}" if [ ! $? -eq 0 ] then echo "could not sync mail with storage" | mail -s "backup error" "backups@alerthost.com" fi echo "#### Mail Backup Finished" >> "${backuplog}" echo "#### Full rsync" >> "${backuplog}" read -s -p "Press enter then unlock key 2x: " rsync -e "ssh -i ${ssh_key_file}" --exclude='lost+found' --no-motd --size-only --log-file="${backuplog}" -rlDvz store.notforyou.com:/data/ /mnt/backup/ --delete --ignore-errors >> "${backuplog}" if [ ! $? -eq 0 ] then echo "could not sync storage with backup drive" | mail -s "backup error" "backups@alerthost.com" fi echo "######## Finished with Backup" >> "${backuplog}" echo "Un-Mounting Drive" >> "${backuplog}" umount /mnt/backup/ >> "${backuplog}" if [ ! $? -eq 0 ] then echo "could not unmount backup drive" | mail -s "backup error" "backups@alerthost.com" fi geli detach /dev/da0 >> "${backuplog}" if [ ! $? -eq 0 ] then echo "could not lock external drive" | mail -s "backup error" "backups@alerthost.com" fi echo "Drive Un-Mounted" >> "${backuplog}" END_BACKUP_DATE=$(date +%Y.%m.%d.%H.%M) echo "End Backup: $END_BACKUP_DATE" >> "${backuplog}" echo "" >> "${backuplog}"