Created
September 11, 2013 08:29
-
-
Save samba/6520800 to your computer and use it in GitHub Desktop.
Backup snapshot script using <fileconvoy.com> as rolling storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script creates encrypted tarballs and then | |
# 1) Emails them to you, or | |
# 2) Uploads them to <fileconvoy.com>, and emails you a link and decryption key | |
# Dependencies: curl, openssl, grep, tar | |
# Where to find the content to back up | |
BACKUP_ROOT=/var/backup | |
# Where to email notifications of backup archives | |
[email protected] | |
# Transmission mode of the archive | |
# Some mail services constrain the size of a file attachment on a message | |
# so this script will upload the file to <fileconvoy.com>, and send the | |
# encryption key with a link instead. | |
# false => send the key, but upload the file | |
# true => send the original file, but not the key | |
EMAIL_ATTACHMENT=false | |
### How long to keep the file on <fileconvoy.com> | |
RETENTION_PERIOD=8670 # 1 year (in hours) | |
# What passphrase to apply on the encrypted archive | |
PASSPHRASE="YourSecret" | |
#### You probably shouldn't change anything below this line. | |
DATE=`date +%Y%m%d-%H%M%S` | |
TMP_ARCHIVE=`mktemp /tmp/backup-${DATE}.tgz.aes.XXXXX` | |
TRANSMIT_FILENAME=archive.tgz.aes | |
upload_fileconvoy () { | |
ENDPOINT='http://www.fileconvoy.com/index.php?Section=68' | |
# KEEP_HOURS=168 # 7 days | |
# KEEP_HOURS=8760 # 1 year | |
KEEP_HOURS=$1 | |
FILENAME=$2; | |
TEMPOUT=`mktemp /tmp/uploadfile.XXXXX` | |
case $FILENAME in | |
-) BASENAME=${TRANSMIT_FILENAME};; | |
*) BASENAME=`basename $2`;; | |
esac | |
curl -F retentionPeriod=${KEEP_HOURS} -F readTermsOfUse=1 -F "upfile_0=@${FILENAME};filename=${BASENAME}" -o ${TEMPOUT} "${ENDPOINT}" | |
grep -A1 'The link or URL you must send to the recipient' ${TEMPOUT} | grep http:// | sed -E 's@</?(center|b)>@@g' | |
rm $TEMPOUT | |
} | |
echo -n "$PASSPHRASE" > ${TMP_ARCHIVE}.key | |
case "${EMAIL_ATTACHMENT}" in | |
true) | |
tar -czf - ${BACKUP_ROOT} | openssl aes-256-cbc -e -pass file:${TMP_ARCHIVE}.key -out ${TMP_ARCHIVE} | |
(echo "Backup archive attached"; uuencode "${TMP_ARCHIVE}" ${TRANSMIT_FILENAME}) | mail -s "Backup archive ${DATE}" ${EMAIL_RECIPIENT} | |
;; | |
*) | |
tar -czf - ${BACKUP_ROOT} | openssl aes-256-cbc -e -pass file:${TMP_ARCHIVE}.key | upload_fileconvoy ${RETENTION_PERIOD} - >${TMP_ARCHIVE}.url | |
(echo "Backup archive: `cat ${TMP_ARCHIVE}.url`"; uuencode "${TMP_ARCHIVE}.key" "archive.key") | mail -s "Backup archive ${DATE}" ${EMAIL_RECIPIENT} | |
;; | |
esac | |
rm -vf ${TMP_ARCHIVE} ${TMP_ARCHIVE}.{key,url} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment