Added variable fields to be easier to adapt file to diferente websites.
This commit is contained in:
@@ -1,17 +1,40 @@
|
||||
# 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
|
||||
|
||||
|
||||
# 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"
|
||||
|
||||
systemctl stop nginx.service # Stop nginx
|
||||
systemctl stop $SERVICE # Stop service
|
||||
|
||||
rm -rf $DEST/* & # Clean destination folder first
|
||||
remove=$! # get the pid number of the cleaning command
|
||||
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
|
||||
wait $dump # and wait for it to finish
|
||||
|
||||
@@ -19,6 +42,7 @@ cp -r $SOURCE $DEST # Copy the website folder to destination
|
||||
copy=$! # get the pid number of the copy command
|
||||
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"
|
||||
logger "Website backed up into $DEST - [WEB-BACKUP]" # Log backup time in journalctl
|
||||
|
Reference in New Issue
Block a user