From 6dba070ca011839b1c13b42799d6be658a66b271 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 29 Jul 2024 17:15:47 +0200 Subject: [PATCH] Added variable fields to be easier to adapt file to diferente websites. --- backing_web.sh | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/backing_web.sh b/backing_web.sh index 293d665..4ca24f7 100644 --- a/backing_web.sh +++ b/backing_web.sh @@ -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 -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" -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 +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 -dump=$! # get the pid number of the database command -wait $dump # and wait for it to finish +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 -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 +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