Skip to content

Instantly share code, notes, and snippets.

@kasparsj
Created October 23, 2015 07:06
Show Gist options
  • Save kasparsj/3e46825542fd9c0eed55 to your computer and use it in GitHub Desktop.
Save kasparsj/3e46825542fd9c0eed55 to your computer and use it in GitHub Desktop.
Backup a directory, copy latest backup to S3
#!/bin/sh
DIR=`/var/www`
NAME=`www`
DATE=`date +%d%m%y%H%M`
S3_BUCKET="s3://my-bucket"
# export files
tar czf /opt/backups/${NAME}_${DATE}.tar -C / ${DIR}
cp /opt/backups/${NAME}_${DATE}.tar /opt/backups/${NAME}-latest.tar
# remove backups older than 5 days
find /opt/backups/${NAME}* -mtime +5 -exec rm {} \;
# sync to amazon
aws s3 cp /opt/backups/${NAME}-latest.tar ${S3_BUCKET}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment