Adapted file so variables can now be input has command line arguments running the file.
This commit is contained in:
@@ -26,23 +26,62 @@ SOURCE="/usr/share/nginx/web_folder" # Source of the website folder
|
|||||||
SERVICE="systemd.service" # Systemd web service
|
SERVICE="systemd.service" # Systemd web service
|
||||||
#---------------------------
|
#---------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# Check for command line arguments -----------------
|
||||||
|
if [ -z "$1" ] # First is database name
|
||||||
|
then
|
||||||
|
DB_S=$DB
|
||||||
|
else
|
||||||
|
DB_S=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$2" ] # Second is database user
|
||||||
|
then
|
||||||
|
DBUSER_S=$DBUSER
|
||||||
|
else
|
||||||
|
DBUSER_S=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$3" ] # Third is database user password
|
||||||
|
then
|
||||||
|
DBPASS_S=$DBPASS
|
||||||
|
else
|
||||||
|
DBPASS_S=$3
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$4" ] # Fourth is destination backup folder
|
||||||
|
then
|
||||||
|
DEST_S=$DEST
|
||||||
|
else
|
||||||
|
DEST_S=$4
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$5" ] # Fifth is source website folder
|
||||||
|
then
|
||||||
|
SOURCE_S=$SOURCE
|
||||||
|
else
|
||||||
|
SOURCE_S=$5
|
||||||
|
fi
|
||||||
|
#---------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
echo -e "Stoping webserver and starting backup procedure...\n"
|
echo -e "Stoping webserver and starting backup procedure...\n"
|
||||||
|
|
||||||
systemctl stop $SERVICE # Stop service
|
systemctl stop $SERVICE # Stop service
|
||||||
|
|
||||||
rm -rf $DEST/* & # Clean destination folder first
|
rm -rf $DEST_S/* & # 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 $DBUSER --password=$DBPASS $DB > $DEST/data_latest.sql & # Get the database to destination
|
mysqldump --user $DBUSER_S --password=$DBPASS_S $DB_S > $DEST_S/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_S $DEST_S # 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 $SERVICE # Start service
|
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
|
logger "Website backed up into $DEST_S - [WEB-BACKUP]" # Log backup time in journalctl
|
||||||
|
Reference in New Issue
Block a user