diff --git a/full_backup b/full_backup index 84c32e3..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 -SYNC="none" # Either 's3sync', 'rsync', or 'none' +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,14 @@ 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" + # See s3sync info in README S3SYNC_PATH="/usr/local/s3sync/s3sync.rb" @@ -62,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 @@ -110,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 @@ -133,6 +171,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