2017-06-05 16:23:04 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
|
|
|
|
# __ __ _ _____ _ _ __ __ _ _ _
|
|
|
|
# \ \ / / | | | __ \ | | | | | \/ | | | | | | |
|
|
|
|
# \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
|
|
|
|
# \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
|
|
|
|
# \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
|
|
|
|
# \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
|
|
|
|
# | |
|
|
|
|
# |_|
|
|
|
|
#/-------------------------------------------------------------------------------------------------------------------------------/
|
|
|
|
#
|
2018-07-05 18:50:36 +00:00
|
|
|
# @version 2.0.0
|
2017-06-05 16:23:04 +00:00
|
|
|
# @build 9th May, 2017
|
|
|
|
# @package Backup System
|
|
|
|
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
|
|
|
# @copyright Copyright (C) 2015. All Rights Reserved
|
|
|
|
# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
#
|
|
|
|
#/-----------------------------------------------------------------------------------------------------------------------------/
|
|
|
|
|
2018-07-05 22:04:44 +00:00
|
|
|
#confirm we are done
|
|
|
|
BACKUPDBDONE=0
|
|
|
|
BACKUPWEBDONE=0
|
|
|
|
|
2017-06-05 16:23:04 +00:00
|
|
|
### MAIN ###
|
|
|
|
function main () {
|
|
|
|
# backup the databases now
|
2018-07-05 22:36:45 +00:00
|
|
|
backupDB
|
2017-06-05 16:23:04 +00:00
|
|
|
# backup the websites now
|
|
|
|
backupWEB
|
|
|
|
}
|
|
|
|
|
2018-07-05 22:36:45 +00:00
|
|
|
function rmTmp () {
|
|
|
|
# trip the switch for the done area
|
|
|
|
if [ "$1" -eq "1" ]; then
|
|
|
|
#confirm we are done
|
|
|
|
BACKUPDBDONE=1
|
|
|
|
elif [ "$1" -eq "2" ]; then
|
|
|
|
#confirm we are done
|
|
|
|
BACKUPWEBDONE=1
|
|
|
|
fi
|
|
|
|
# only if both are done
|
|
|
|
if [ "$BACKUPWEBDONE" -eq "1" ] && [ "$BACKUPDBDONE" -eq "1" ]; then
|
|
|
|
# now remove the local file
|
|
|
|
rmFolder "$tmpFolder"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-06-05 16:23:04 +00:00
|
|
|
# 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
|
2018-07-04 13:27:40 +00:00
|
|
|
|
2017-06-05 16:23:04 +00:00
|
|
|
# start fresh
|
2018-07-04 13:27:40 +00:00
|
|
|
cd "$USERHOME"
|
2017-06-05 16:23:04 +00:00
|
|
|
# GO To remote server and do house cleaning
|
2018-07-05 03:27:01 +00:00
|
|
|
if [ "$BACKUPTYPE" -eq "1" ]; then
|
|
|
|
ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEDBPATH"
|
|
|
|
fi
|
2018-07-05 22:04:44 +00:00
|
|
|
# try to remove tmp
|
2018-07-05 22:36:45 +00:00
|
|
|
rmTmp 1
|
2017-06-05 16:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# function to backup all WEB folders
|
|
|
|
function backupWEB () {
|
2018-07-05 03:27:01 +00:00
|
|
|
# GO To remote server and do house cleaning
|
2017-06-05 16:23:04 +00:00
|
|
|
while IFS=$'\t' read -r -a foalder
|
|
|
|
do
|
|
|
|
[[ "$foalder" =~ ^#.*$ ]] && continue
|
|
|
|
# move the local folder & files to remote
|
|
|
|
moveWEB "${foalder[0]}" "${foalder[1]}"
|
2018-07-05 03:27:01 +00:00
|
|
|
|
2017-06-05 16:23:04 +00:00
|
|
|
done < $folderBuilder
|
2018-07-05 03:27:01 +00:00
|
|
|
|
2017-06-05 16:23:04 +00:00
|
|
|
# start fresh
|
2018-07-04 13:27:40 +00:00
|
|
|
cd "$USERHOME"
|
2017-06-05 16:23:04 +00:00
|
|
|
# GO To remote server and do house cleaning
|
2018-07-05 03:27:01 +00:00
|
|
|
if [ "$BACKUPTYPE" -eq "1" ]; then
|
|
|
|
ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEWEBPATH"
|
|
|
|
fi
|
2018-07-05 22:04:44 +00:00
|
|
|
# try to remove tmp
|
2018-07-05 22:36:45 +00:00
|
|
|
rmTmp 2
|
2017-06-05 16:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# run the main only at the end!
|
|
|
|
main
|
2018-07-05 22:36:45 +00:00
|
|
|
|
|
|
|
# try again
|
|
|
|
rmTmp 3
|