Last active
December 27, 2015 10:39
-
-
Save andrezrv/7313107 to your computer and use it in GitHub Desktop.
Make a complete backup of your production website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment