From 8d694948ae03bfb605fbae94caa926ed0e9787e9 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 18 Oct 2023 16:54:51 +0000 Subject: [PATCH] First commit of the bash file. --- backing_web.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 backing_web.sh diff --git a/backing_web.sh b/backing_web.sh new file mode 100644 index 0000000..293d665 --- /dev/null +++ b/backing_web.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +DEST="/home/user/backups/daily/latest" # Backup folder +SOURCE="/usr/share/nginx/web_folder" # Source of the website folder + +echo -e "Stoping webserver and starting backup procedure...\n" + +systemctl stop nginx.service # Stop nginx + +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 + +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 + +echo -e "Website backed up\nWebserver back online.\n"