Skip to content

Instantly share code, notes, and snippets.

@crudh
Created September 25, 2013 08:26
Show Gist options
  • Save crudh/6696672 to your computer and use it in GitHub Desktop.
Save crudh/6696672 to your computer and use it in GitHub Desktop.
Directory backup by mail (make sure mailx is installed and in the path).
#!/bin/sh
# CONFIGURE THIS
inputDir=/var/system
outputDir=/tmp
resultPrefix=system
mailSubject="Backup - system"
mailBody="Backup - system"
mailRecipient=christian@primian.se
# DO NOT CHANGE BELOW HERE--------------------------
current=`date +"%Y%m%d-%H%M"`
outputFile=$outputDir/$resultPrefix-$current.tar.bz2
# Create the folder
mkdir -p $outputDir
# Create the archive file
tar -c --bzip2 -f $outputFile $inputDir >/dev/null 2>&1
# Mail the file
echo "$mailBody" | mailx -s "$mailSubject" -a "$outputFile" $mailRecipient
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment