Added variable fields to be easier to adapt file to diferente websites.
This commit is contained in:
@@ -1,24 +1,48 @@
|
|||||||
|
# backing.sh
|
||||||
|
# ---------------------
|
||||||
|
#
|
||||||
|
# Backup a website folder and its database
|
||||||
|
#
|
||||||
|
# SYNOPSIS
|
||||||
|
# backing.sh [DB] [DBUSER] [DBPASS] [DEST] [SOURCE]
|
||||||
|
#
|
||||||
|
# This file can be used in two ways,
|
||||||
|
# -- Input the variables in the command line with the above synopsis
|
||||||
|
# -- Or run the file without any arguments and edit the variables below
|
||||||
|
#
|
||||||
|
# !!!Make sure the destination folder exists!!!
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
DEST="/home/user/backups/daily/latest" # Backup folder
|
|
||||||
SOURCE="/usr/share/nginx/web_folder" # Source of the website folder
|
# Variables ----------------
|
||||||
|
DB="database" # Database name
|
||||||
|
DBUSER="databaseUser" # Database user
|
||||||
|
DBPASS="databasePass" # Database user password
|
||||||
|
DEST="/home/user/backups/daily/latest" # Backup folder
|
||||||
|
SOURCE="/usr/share/nginx/web_folder" # Source of the website folder
|
||||||
|
SERVICE="systemd.service" # Systemd web service
|
||||||
|
#---------------------------
|
||||||
|
|
||||||
echo -e "Stoping webserver and starting backup procedure...\n"
|
echo -e "Stoping webserver and starting backup procedure...\n"
|
||||||
|
|
||||||
systemctl stop nginx.service # Stop nginx
|
systemctl stop $SERVICE # Stop service
|
||||||
|
|
||||||
rm -rf $DEST/* & # Clean destination folder first
|
rm -rf $DEST/* & # Clean destination folder first
|
||||||
remove=$! # get the pid number of the cleaning command
|
remove=$! # get the pid number of the cleaning command
|
||||||
wait $remove # and wait for it to finish
|
wait $remove # and wait for it to finish
|
||||||
|
|
||||||
mysqldump --user user --password=password > $DEST/data_latest.sql & # Get the database to destination
|
mysqldump --user $DBUSER --password=$DBPASS $DB > $DEST/data_latest.sql & # Get the database to destination
|
||||||
dump=$! # get the pid number of the database command
|
dump=$! # get the pid number of the database command
|
||||||
wait $dump # and wait for it to finish
|
wait $dump # and wait for it to finish
|
||||||
|
|
||||||
cp -r $SOURCE $DEST # Copy the website folder to destination
|
cp -r $SOURCE $DEST # Copy the website folder to destination
|
||||||
copy=$! # get the pid number of the copy command
|
copy=$! # get the pid number of the copy command
|
||||||
wait $copy # and wait for it to finish
|
wait $copy # and wait for it to finish
|
||||||
|
|
||||||
systemctl start nginx.service # Start nginx
|
systemctl start $SERVICE # Start service
|
||||||
|
|
||||||
echo -e "Website backed up\nWebserver back online.\n"
|
echo -e "Website backed up\nWebserver back online.\n"
|
||||||
|
logger "Website backed up into $DEST - [WEB-BACKUP]" # Log backup time in journalctl
|
||||||
|
Reference in New Issue
Block a user