Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions full_backup
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down