diff --git a/README.md b/README.md index 1600fed..25c8191 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,8 @@ With your cron time, add the following line to the crontab, using your path deta **Debian & Ubuntu Linux:** ```bash - sudo apt-get install bash (Probably BASH is already installed on your system) - sudo apt-get install git + $ sudo apt-get install bash (Probably BASH is already installed on your system) + $ sudo apt-get install git ``` # Copyright: diff --git a/config.txt b/config.txt index 0621f40..7b46d7d 100644 --- a/config.txt +++ b/config.txt @@ -8,10 +8,21 @@ #### just update these to point to your server ### ############################################################## +## BACKUP TYPE (1 = REMOTE SERVER || 2 = DROPBOX) +BACKUPTYPE=1 + +## REMOTE SERVER DETAILS (1) REMOTESSH="user@yourserver.com" + +## DROPBOX DETAILS (2) (get it from https://github.com/andreafabrizi/Dropbox-Uploader) +DROPBOX="/home/path/to/Dropbox-Uploader/dropbox_uploader.sh" + +# PATH DETAILS REMOTEDBPATH="your_db_path/" -REMOTEWEBPATH="your_website_pat/" +REMOTEWEBPATH="your_website_path/" + +## WEBSITE BACKUP TYPE (1 = PER/FILE || 2 = ZIPPED) +WEBBACKUPTYPE=1 ## 0 = no date | 1 = year | 2 = year-month | 3 = your-month-day | 4 = your-month-day:time # For DB file name USEDATE=0 - diff --git a/incl.sh b/incl.sh index 2bf9b94..1b59427 100644 --- a/incl.sh +++ b/incl.sh @@ -54,7 +54,7 @@ function zipDB { # the user password PASS="$5" # use this command for a database server on localhost. add other options if need be. - mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} > ${FILE} + mysqldump --opt -q --user=${USER} --password=${PASS} ${DATABASE} > ${FILE} # gzip the mysql database dump file gzip $FILE # return file name @@ -67,7 +67,11 @@ function moveDB () { # file name FILE="$1" # move file - scp "$FILE" "$REMOTESSH:${REMOTEDBPATH}${FILE}" + if [ "$BACKUPTYPE" -eq "2" ]; then + $DROPBOX -q upload "$FILE" "${REMOTEDBPATH}${FILE}" + else + scp "$FILE" "$REMOTESSH:${REMOTEDBPATH}${FILE}" + fi } function moveWEB () { @@ -75,8 +79,36 @@ function moveWEB () { localFolder="$1" # remote folder name remoteFolder="$2" + # check if we should instead zip + if [ "$WEBBACKUPTYPE" -eq "2" ]; then + # set the file name + if [ "$USEDATE" -eq "4" ]; then + FILE=`date +"%Y-%m-%d:%H:%M:%S"`"_$2.zip" + elif [ "$USEDATE" -eq "3" ]; then + FILE=`date +"%Y-%m-%d"`"_$2.zip" + elif [ "$USEDATE" -eq "2" ]; then + FILE=`date +"%Y-%m"`"_$2.zip" + elif [ "$USEDATE" -eq "1" ]; then + FILE=`date +"%Y"`"_$2.zip" + else + FILE="$2.zip" + fi + # zip the website + zip -r -q "${localFolder}${FILE}" "${localFolder}" + # set the paths + PaTh="${localFolder}${FILE}" + remotePaTh="${REMOTEWEBPATH}${FILE}" + else + # set the paths + PaTh="${localFolder}" + remotePaTh="${REMOTEWEBPATH}${remoteFolder}" + fi # move all file & folders - rsync -ax "${localFolder}" "$REMOTESSH:${REMOTEWEBPATH}${remoteFolder}" + if [ "$BACKUPTYPE" -eq "2" ]; then + $DROPBOX -q upload "${PaTh}" "${remotePaTh}" + else + rsync -ax "${PaTh}" "$REMOTESSH:${remotePaTh}" + fi } function remoteHouseCleaning () { diff --git a/main.sh b/main.sh index cba2ad9..fc41c03 100644 --- a/main.sh +++ b/main.sh @@ -10,7 +10,7 @@ # |_| #/-------------------------------------------------------------------------------------------------------------------------------/ # -# @version 1.0.0 +# @version 1.0.0 # @build 9th May, 2017 # @package Backup System # @author Llewellyn van der Merwe @@ -44,23 +44,28 @@ function backupDB () { # start fresh cd "$USERHOME" # GO To remote server and do house cleaning - ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEDBPATH" + if [ "$BACKUPTYPE" -eq "1" ]; then + ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEDBPATH" + fi } # function to backup all WEB folders function backupWEB () { + # GO To remote server and do house cleaning while IFS=$'\t' read -r -a foalder do [[ "$foalder" =~ ^#.*$ ]] && continue # move the local folder & files to remote moveWEB "${foalder[0]}" "${foalder[1]}" - + done < $folderBuilder - + # start fresh cd "$USERHOME" # GO To remote server and do house cleaning - ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEWEBPATH" + if [ "$BACKUPTYPE" -eq "1" ]; then + ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEWEBPATH" + fi } # run the main only at the end! diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..fc41c03 --- /dev/null +++ b/setup.sh @@ -0,0 +1,72 @@ +#!/bin/bash +#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/ +# __ __ _ _____ _ _ __ __ _ _ _ +# \ \ / / | | | __ \ | | | | | \/ | | | | | | | +# \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| | +# \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` | +# \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| | +# \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_| +# | | +# |_| +#/-------------------------------------------------------------------------------------------------------------------------------/ +# +# @version 1.0.0 +# @build 9th May, 2017 +# @package Backup System +# @author Llewellyn van der Merwe +# @copyright Copyright (C) 2015. All Rights Reserved +# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html +# +#/-----------------------------------------------------------------------------------------------------------------------------/ + +### MAIN ### +function main () { + # backup the databases now + backupDB & + # backup the websites now + backupWEB +} + +# function to backup all DB's +function backupDB () { + while IFS=$'\t' read -r -a database + do + [[ "$database" =~ ^#.*$ ]] && continue + # zip the database + DBFILE=$(zipDB "${database[0]}" "${database[1]}" "${database[2]}" "${database[3]}" "${database[4]}") + # move to backup server + moveDB "$DBFILE" + done < $databaseBuilder + + # now remove the local file + rmTmpFolder "$tmpFolder" + + # start fresh + cd "$USERHOME" + # GO To remote server and do house cleaning + if [ "$BACKUPTYPE" -eq "1" ]; then + ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEDBPATH" + fi +} + +# function to backup all WEB folders +function backupWEB () { + # GO To remote server and do house cleaning + while IFS=$'\t' read -r -a foalder + do + [[ "$foalder" =~ ^#.*$ ]] && continue + # move the local folder & files to remote + moveWEB "${foalder[0]}" "${foalder[1]}" + + done < $folderBuilder + + # start fresh + cd "$USERHOME" + # GO To remote server and do house cleaning + if [ "$BACKUPTYPE" -eq "1" ]; then + ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEWEBPATH" + fi +} + +# run the main only at the end! +main