Skip to content

Instantly share code, notes, and snippets.

@adionditsak
Last active August 29, 2015 13:56
Show Gist options
  • Save adionditsak/8843493 to your computer and use it in GitHub Desktop.
Save adionditsak/8843493 to your computer and use it in GitHub Desktop.
Backup valuable content swiftly without much struggle
#!/usr/bin/env bash
#### DEPENDENCIES: mutt
#### VARS
[email protected]
DATE=$(date +%Y-%m-%d)
LOCAL_BACKUP=/path/to/backup
LOCAL_ARCHIVE=$HOME/backup-${DATE}.tar.gz
#### FUNCTIONS
function main() {
archive
mail
delete_locally
}
function archive() {
echo "Archiving your files from ${LOCAL_BACKUP}- "
tar -czvf ${LOCAL_ARCHIVE} ${LOCAL_BACKUP}
echo "Done"
}
function mail() {
echo "Sending e-mail with backup ${LOCAL_ARCHIVE} - "
if [ -f ${LOCAL_ARCHIVE} ]; then
echo "Backup of files from ${DATE}" | mutt -s "BACKUP OF: ${LOCAL_ARCHIVE}" -a ${LOCAL_ARCHIVE} -- ${MAIL}
echo "Done"
else
echo "Could not find archive at ${LOCAL_ARCHIVE}"
exit
fi
}
function delete_locally() {
echo "Removing ${LOCAL_ARCHIVE} locally - "
rm -f ${LOCAL_ARCHIVE}
echo "Done"
}
#### INIT
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment