diff --git a/backing_web.sh b/backing_web.sh index 4ca24f7..e560bc4 100644 --- a/backing_web.sh +++ b/backing_web.sh @@ -18,31 +18,70 @@ # 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 +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 #--------------------------- + +# 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" 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_S/* & # Clean destination folder first +remove=$! # get the pid number of the cleaning command +wait $remove # 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 +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 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 wait $copy # and wait for it to finish 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 +logger "Website backed up into $DEST_S - [WEB-BACKUP]" # Log backup time in journalctl