From 4212d5ee4919f6253c916876bbdcb9b321e1b013 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 16 Jul 2018 00:30:21 +0200 Subject: [PATCH] Added the option to only do database or website/files incase you only want to do on or the other --- config.txt | 4 +++ main.sh | 31 +++++++++++++---- run.sh | 52 ++++++++++++++++++++-------- setup.sh | 100 ++++++++++++++++++++++++++++++++++++----------------- 4 files changed, 135 insertions(+), 52 deletions(-) diff --git a/config.txt b/config.txt index b32a08d..5ebd979 100644 --- a/config.txt +++ b/config.txt @@ -11,6 +11,10 @@ ## BACKUP TYPE (1 = REMOTE SERVER || 2 = DROPBOX) BACKUPTYPE=1 +## BACKUP AREAS +BACKUPWEBSITES=1 +BACKUPDATABASE=1 + ## REMOTE SERVER DETAILS (1) REMOTESSH="user@yourserver.com" diff --git a/main.sh b/main.sh index c5ac079..cb8a505 100644 --- a/main.sh +++ b/main.sh @@ -19,9 +19,18 @@ # #/-----------------------------------------------------------------------------------------------------------------------------/ -#confirm we are done -BACKUPDBDONE=0 -BACKUPWEBDONE=0 +#confirm we are done with database backup +if [ "$BACKUPDATABASE" -eq "1" ]; then + BACKUPDBDONE=0 +else + BACKUPDBDONE=1 +fi +#confirm we are done with website backup + if [ "$BACKUPWEBSITES" -eq "1" ]; then + BACKUPWEBDONE=0 +else + BACKUPWEBDONE=1 +fi # some error handle MOVEDBRESULT=0 @@ -36,14 +45,22 @@ function main () { # do backup if [ "$REVERT" -ne 1 ]; then # backup the databases now - backupDB + if [ "$BACKUPDATABASE" -eq "1" ]; then + backupDB + fi # backup the websites now - backupWEB + if [ "$BACKUPWEBSITES" -eq "1" ]; then + backupWEB + fi else # revert the databases now - revertDB + if [ "$BACKUPDATABASE" -eq "1" ]; then + revertDB + fi # revert the websites now - revertWEB + if [ "$BACKUPWEBSITES" -eq "1" ]; then + revertWEB + fi # force remove tmp rmTmp 4 fi diff --git a/run.sh b/run.sh index e9098f3..0338454 100755 --- a/run.sh +++ b/run.sh @@ -44,6 +44,24 @@ fi # load functions . "$DIR/incl.sh" +# check if the BACKUPWEBSITES area switches is set +if [ -z ${BACKUPWEBSITES+x} ]; then + echo "BACKUPWEBSITES=1" >> "$DIR/config.sh" + BACKUPWEBSITES=1 +fi + +# check if the BACKUPDATABASE area switches is set +if [ -z ${BACKUPDATABASE+x} ]; then + echo "BACKUPDATABASE=1" >> "$DIR/config.sh" + BACKUPDATABASE=1 +fi + + # need only continue if either one option is set +if [ "$BACKUPWEBSITES" -eq "0" ] && [ "$BACKUPDATABASE" -eq "0" ]; then + # We have no work here + exit 0 +fi + # got to script folder cd "$DIR" # set Base Dir @@ -59,22 +77,28 @@ then mkdir -p "$tmpFolder" fi -# DB file -databasesFileName="databases" -databaseBuilder="$BASEDIR/$databasesFileName" -# check if file exist -if [ ! -f "$databaseBuilder" ] -then - runSetup 2 "$databaseBuilder" +# only add if db's are required +if [ "$BACKUPDATABASE" -eq "1" ]; then + # DB file + databasesFileName="databases" + databaseBuilder="$BASEDIR/$databasesFileName" + # check if file exist + if [ ! -f "$databaseBuilder" ] + then + runSetup 2 "$databaseBuilder" + fi fi -# folder names -foldersFileName="folders" -folderBuilder="$BASEDIR/$foldersFileName" -# check if file exist -if [ ! -f "$folderBuilder" ] -then - runSetup 3 "$folderBuilder" +# only add if db's are required +if [ "$BACKUPWEBSITES" -eq "1" ]; then + # folder names + foldersFileName="folders" + folderBuilder="$BASEDIR/$foldersFileName" + # check if file exist + if [ ! -f "$folderBuilder" ] + then + runSetup 3 "$folderBuilder" + fi fi # we move to user folder diff --git a/setup.sh b/setup.sh index e25f890..57076d2 100644 --- a/setup.sh +++ b/setup.sh @@ -69,37 +69,71 @@ function runSetupConfig () { # set default dropbox details INPUT_DROPBOX="/home/path/to/Dropbox-Uploader/dropbox_uploader.sh" fi - # get the remote database backup paths - echo -ne "\n Set Remote Backup Path for Database Backups\n" - echo -ne " # Default (db_path/): " - read -r INPUT_REMOTEDBPATH - # set default - INPUT_REMOTEDBPATH=${INPUT_REMOTEDBPATH:-'db_path/'} - # get the remote website backup paths - echo -ne "\n Set Remote Backup Path for Website Backups\n" - echo -ne " # Default (website_path/): " - read -r INPUT_REMOTEWEBPATH - # set default - INPUT_REMOTEWEBPATH=${INPUT_REMOTEWEBPATH:-'website_path/'} - # select the website backup type - echo -ne "\n Select the Website Backup Type\n" - echo -ne " 1 = per/file\n" - echo -ne " 2 = zipped package (default)\n" - echo -ne " # Make your selection [1/2]: " - read -r INPUT_WEBBACKUPTYPE - # set default - INPUT_WEBBACKUPTYPE=${INPUT_WEBBACKUPTYPE:-2} - # select the backup file name convention - echo -ne "\n Select the Backup File Name Convention\n" - echo -ne " 0 = add no date\n" - echo -ne " 1 = add only year (default)\n" - echo -ne " 2 = add year & month\n" - echo -ne " 3 = add year, month & day\n" - echo -ne " 4 = add year, month, day & time\n" - echo -ne " # Make your selection [1-4]: " - read -r INPUT_USEDATE - # set default - INPUT_USEDATE=${INPUT_USEDATE:-1} + # Check if there is database backups + INPUT_BACKUPDATABASE=1 + echo "" + echo -ne "\n Would you like to Backup Database/s? [y/N]: " + read -r answer + if [[ $answer != "y" ]]; then + # set backup to null + INPUT_BACKUPDATABASE=0 + fi + # only add if db backups are required + if [ "$INPUT_BACKUPDATABASE" -eq "1" ]; then + # get the remote database backup paths + echo -ne "\n Set Remote Backup Path for Database Backups\n" + echo -ne " # Default (db_path/): " + read -r INPUT_REMOTEDBPATH + # set default + INPUT_REMOTEDBPATH=${INPUT_REMOTEDBPATH:-'db_path/'} + else + INPUT_REMOTEDBPATH='db_path/' + fi + # Check if there is website backups + INPUT_BACKUPWEBSITES=1 + echo "" + echo -ne "\n Would you like to backup Files/Website? [y/N]: " + read -r answer + if [[ $answer != "y" ]]; then + # set backup to null + INPUT_BACKUPWEBSITES=0 + fi + # only add if website backups are required + if [ "$INPUT_BACKUPWEBSITES" -eq "1" ]; then + # get the remote website backup paths + echo -ne "\n Set Remote Backup Path for Files/Website Backups\n" + echo -ne " # Default (website_path/): " + read -r INPUT_REMOTEWEBPATH + # set default + INPUT_REMOTEWEBPATH=${INPUT_REMOTEWEBPATH:-'website_path/'} + # select the website backup type + echo -ne "\n Select the Files/Website Backup Type\n" + echo -ne " 1 = per/file\n" + echo -ne " 2 = zipped package (default)\n" + echo -ne " # Make your selection [1/2]: " + read -r INPUT_WEBBACKUPTYPE + # set default + INPUT_WEBBACKUPTYPE=${INPUT_WEBBACKUPTYPE:-2} + else + INPUT_REMOTEWEBPATH='website_path/' + INPUT_WEBBACKUPTYPE=2 + fi + # need only ask this if either one option is set + if [ "$INPUT_BACKUPWEBSITES" -eq "1" ] || [ "$INPUT_BACKUPDATABASE" -eq "1" ]; then + # select the backup file name convention + echo -ne "\n Select the Backup File Name Convention for zip Packages\n" + echo -ne " 0 = add no date\n" + echo -ne " 1 = add only year (default)\n" + echo -ne " 2 = add year & month\n" + echo -ne " 3 = add year, month & day\n" + echo -ne " 4 = add year, month, day & time\n" + echo -ne " # Make your selection [1-4]: " + read -r INPUT_USEDATE + # set default + INPUT_USEDATE=${INPUT_USEDATE:-1} + else + INPUT_USEDATE=1 + fi # now add it all to the config file echo "#!/bin/bash" > "$1" @@ -115,6 +149,10 @@ function runSetupConfig () { echo "## BACKUP TYPE (1 = REMOTE SERVER || 2 = DROPBOX)" >> "$1" echo "BACKUPTYPE=${INPUT_BACKUPTYPE}" >> "$1" echo "" >> "$1" + echo "## BACKUP AREAS" >> "$1" + echo "BACKUPWEBSITES=${INPUT_BACKUPWEBSITES}" >> "$1" + echo "BACKUPDATABASE=${INPUT_BACKUPDATABASE}" >> "$1" + echo "" >> "$1" echo "## REMOTE SERVER DETAILS (1)" >> "$1" echo "REMOTESSH=\"${INPUT_REMOTESSH}\"" >> "$1" echo "" >> "$1"