Skip to content

Instantly share code, notes, and snippets.

@wabarr
Last active August 29, 2015 14:01
Show Gist options
  • Save wabarr/cc219621a208244510e8 to your computer and use it in GitHub Desktop.
Save wabarr/cc219621a208244510e8 to your computer and use it in GitHub Desktop.
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 protected] -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 protected] -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