Skip to content

Instantly share code, notes, and snippets.

@wabarr wabarr/backup.sh
Last active Aug 29, 2015

Embed
What would you like to do?
shell script to check if sqlite database has changed, and to email the backup file if so
#get the current md5sum, and use awk to strip out filename, which is reuturned as well
#note, this assumes that md5sum_of_database_at_last_backup.txt exists and contains the hash of db at last backup
#currently no error checking
currentMD5=$(md5sum test.db | awk '{print $1}')
lastMD5=$(cat /home/user/md5sum_of_database_at_last_backup.txt)
if [ "$currentMD5" == "$lastMD5" ]
then
echo | mutt email@gmail.com -s "database has not changed since last backup"
else
#update the database
echo $currentMD5 > /home/user/md5sum_of_database_at_last_backup.txt
#send db as email attachment
echo | mutt email@gmail.com -a /home/user/test.db -s "daily database backup"
fi
unset currentMD5
unset lastMD5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.