From 4d46a50a8b7ff505b38512f8d774b8603c3ab37c Mon Sep 17 00:00:00 2001 From: Ralph Huwiler Date: Mon, 1 Feb 2016 19:18:15 +0100 Subject: [PATCH 1/2] sync with s3cmd --- full_backup | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/full_backup b/full_backup index 84c32e3..444e07d 100755 --- a/full_backup +++ b/full_backup @@ -5,7 +5,7 @@ BACKUP_DIR="/backups/site_backups" # The directory in which you want backups placed DUMP_MYSQL=true TAR_SITES=false -SYNC="none" # Either 's3sync', 'rsync', or 'none' +SYNC="none" # Either 's3cmd', 's3sync', 'rsync', or 'none' KEEP_MYSQL="14" # How many days worth of mysql dumps to keep KEEP_SITES="2" # How many days worth of site tarballs to keep @@ -17,6 +17,10 @@ MYSQL_BACKUP_DIR="$BACKUP_DIR/mysql/" SITES_DIR="/var/www/sites/" SITES_BACKUP_DIR="$BACKUP_DIR/sites/" +#S3CMD +S3CMD_PATH="$(which s3cmd)" +S3CMD_S3_BUCKET="tesla.rhwilr.ch" + # See s3sync info in README S3SYNC_PATH="/usr/local/s3sync/s3sync.rb" @@ -133,6 +137,14 @@ elif [[ "$SYNC" == "s3sync" ]] echo "------------------------------------" echo "Sending backups to s3..." $S3SYNC_PATH --delete -v $SSL_OPTION -r $BACKUP_DIR/ $S3_BUCKET:backups + +# OR sync to S3 with s3cmd +elif [[ "$SYNC" == "s3cmd" ]] + then + echo "------------------------------------" + echo "Sending backups to s3..." + $S3CMD_PATH sync --delete-removed $BACKUP_DIR/ s3://$S3CMD_S3_BUCKET/backups/ + fi # Announce the completion time From 0fd0c55e15b1eddc4f9c8cbdcd9a04425ad8c29d Mon Sep 17 00:00:00 2001 From: Ralph Huwiler Date: Wed, 17 Feb 2016 10:36:16 +0100 Subject: [PATCH 2/2] support for letsencrypt backup --- full_backup | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/full_backup b/full_backup index 444e07d..2cc0ec5 100755 --- a/full_backup +++ b/full_backup @@ -2,12 +2,16 @@ # BEGIN CONFIGURATION ========================================================== -BACKUP_DIR="/backups/site_backups" # The directory in which you want backups placed +BACKUP_DIR="/backups" # The directory in which you want backups placed DUMP_MYSQL=true TAR_SITES=false +TAR_LETSENCRYPT=false + SYNC="none" # Either 's3cmd', 's3sync', 'rsync', or 'none' + KEEP_MYSQL="14" # How many days worth of mysql dumps to keep -KEEP_SITES="2" # How many days worth of site tarballs to keep +KEEP_SITES="14" # How many days worth of site tarballs to keep +KEEP_LETSENCRYPT="120" MYSQL_HOST="localhost" MYSQL_USER="root" @@ -17,6 +21,10 @@ MYSQL_BACKUP_DIR="$BACKUP_DIR/mysql/" SITES_DIR="/var/www/sites/" SITES_BACKUP_DIR="$BACKUP_DIR/sites/" +LETSENCRYPT_DIR="/etc/letsencrypt/" +LETSENCRYPT_BACKUP_DIR="$BACKUP_DIR/letsencrypt/" + + #S3CMD S3CMD_PATH="$(which s3cmd)" S3CMD_S3_BUCKET="tesla.rhwilr.ch" @@ -66,6 +74,11 @@ if [[ ! -d $SITES_BACKUP_DIR ]] then mkdir -p "$SITES_BACKUP_DIR" fi +if [[ ! -d $LETSENCRYPT_BACKUP_DIR ]] + then + mkdir -p "$LETSENCRYPT_BACKUP_DIR" +fi + if [ "$DUMP_MYSQL" = "true" ] then @@ -114,6 +127,27 @@ if [ "$TAR_SITES" == "true" ] fi +if [ "$TAR_LETSENCRYPT" == "true" ] + then + + # Create tar of letsencrypt directory. + echo "------------------------------------" + cd $LETSENCRYPT_DIR + + echo "Archiving Let's Encrypt..." + $TAR_PATH --exclude="*/log" -czf $LETSENCRYPT_BACKUP_DIR$THE_DATE.tgz $LETSENCRYPT_DIR + + # Delete old letsencrypt backups + echo "------------------------------------" + echo "Deleting old backups..." + # List files to be deleted to stdout (for report) + $FIND_PATH $LETSENCRYPT_BACKUP_DIR*.tgz -mtime +$KEEP_LETSENCRYPT + # Delete files older than specified number of days + $FIND_PATH $LETSENCRYPT_BACKUP_DIR*.tgz -mtime +$KEEP_LETSENCRYPT -exec rm {} + + +fi + + # Rsync everything with another server if [[ "$SYNC" == "rsync" ]] then