Make a complete backup of your production website.
#!/bin/bash
# website-switch.sh
#
# This task assumes you're using NGINX as your web server.
# /etc/nginx/sites-available/$WORKING_FILE_NAME is the working configuration file for your website.
# It is symlinked from /etc/nginx/sites-enabled/$WORKING_FILE_NAME.
# /etc/nginx/sites-available/$BACKGROUND_FILE_NAME is an alternative configuration file,
# where you point to a maintenance version of your website.
#
# Configure your settings.
WORKING_FILE_NAME=website
BACKGROUND_FILE_NAME=website-background
TRANSITION_FILE_NAME=website-transition
# Move your current working configuration file to a third location.
mv /etc/nginx/sites-available/$WORKING_FILE_NAME /etc/nginx/sites-available/$TRANSITION_FILE_NAME
# Move your background configuration file to your working location.
mv /etc/nginx/sites-available/$BACKGROUND_FILE_NAME /etc/nginx/sites-available/$WORKING_FILE_NAME
# Move your file kept in transition to background location.
mv /etc/nginx/sites-available/$TRANSITION_FILE_NAME /etc/nginx/sites-available/$BACKGROUND_FILE_NAME
# Reload NGINX configuration.
service nginx reload
#!/bin/bash
# website-full-backup.sh
#
# Make a complete backup of your production website.
#
# Put your website in maintenance state.
sh website-switch.sh
# Backup your files.
sh website-backup-application.sh
# Backup your dtabase.
sh website-backup-database.sh
# Put your website back on its working state.
sh website-switch.sh
#!/bin/bash
# website-backup-database.sh
#
# Quickly backup your website's database.
# This task assumes you have mysql and gzip installed.
#
# Configure your settings.
DATE=$(date +"%Y%m%d%H%M")
DB_USER=root
DB_PASSWORD=blank
DB_NAME=local_db
BACKUP_PATH=/srv/www/website/backups/dumps
# Backup your files to your selected folder using mysqldump and gzip.
mysqldump -u $DB_USER -p$DB_PASSWORD $DB_NAME | gzip > $BACKUP_PATH\/$DATE\.sql.gz
# Clean the backup directory, saving only the last 3 backups.
cd $BACKUP_PATH; (ls -t|head -n 3;ls)|sort|uniq -u|xargs rm
#!/bin/bash
# website-backup-application.sh
#
# Quickly backup the files of your website.
# This task assumes you have zip installed.
#
# Configure your settings.
DATE=$(date +"%Y%m%d%H%M")
APPLICATION_PATH=/srv/www/website/application
BACKUP_PATH=/srv/www/website/backups/application
# Backup your files to your selected folder using zip.
zip $BACKUP_PATH\/$DATE\.zip $APPLICATION_PATH
# Clean the backup directory, saving only the last 3 backups.
cd $BACKUP_PATH; (ls -t|head -n 3;ls)|sort|uniq -u|xargs rm
# Add scripts to /usr/bin
ln -s /srv/www/website/tasks/website-backup-applications.sh /usr/bin/website-backup-applications
ln -s /srv/www/website/tasks/website-backup-database.sh /usr/bin/website-backup-database
ln -s /srv/www/website/tasks/website-full-backup.sh /usr/bin/website-full-backup
ln -s /srv/www/website/tasks/website-switch.sh /usr/bin/website-switch