Adapted the script to run more stable

This commit is contained in:
Llewellyn van der Merwe 2018-07-04 15:27:40 +02:00
parent 80b174a05b
commit a1ccfe850c
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
4 changed files with 21 additions and 14 deletions

View File

@ -16,7 +16,7 @@ The Bash scripts used to backup database and folders on a server
Clone Repository Clone Repository
```bash ```bash
$ git clone ssh://git@projects.vdm.io/system-backup.git system-backup $ git clone ssh://git@github.com:vdm-io/Backup-System.git system-backup
``` ```
Rename __config.txt__ to __config.sh__ and update the values in the file. Rename __config.txt__ to __config.sh__ and update the values in the file.

0
incl.sh Executable file → Normal file
View File

11
main.sh Executable file → Normal file
View File

@ -22,7 +22,7 @@
### MAIN ### ### MAIN ###
function main () { function main () {
# backup the databases now # backup the databases now
backupDB backupDB &
# backup the websites now # backup the websites now
backupWEB backupWEB
} }
@ -36,12 +36,13 @@ function backupDB () {
DBFILE=$(zipDB "${database[0]}" "${database[1]}" "${database[2]}" "${database[3]}" "${database[4]}") DBFILE=$(zipDB "${database[0]}" "${database[1]}" "${database[2]}" "${database[3]}" "${database[4]}")
# move to backup server # move to backup server
moveDB "$DBFILE" moveDB "$DBFILE"
# now remove the local file
rmTmpFolder "$tmpFolder"
done < $databaseBuilder done < $databaseBuilder
# now remove the local file
rmTmpFolder "$tmpFolder"
# start fresh # start fresh
cd "$DIR" cd "$USERHOME"
# GO To remote server and do house cleaning # GO To remote server and do house cleaning
ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEDBPATH" ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEDBPATH"
} }
@ -57,7 +58,7 @@ function backupWEB () {
done < $folderBuilder done < $folderBuilder
# start fresh # start fresh
cd "$DIR" cd "$USERHOME"
# GO To remote server and do house cleaning # GO To remote server and do house cleaning
ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEWEBPATH" ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEWEBPATH"
} }

22
run.sh Executable file → Normal file
View File

@ -19,6 +19,8 @@
# #
#/-----------------------------------------------------------------------------------------------------------------------------/ #/-----------------------------------------------------------------------------------------------------------------------------/
# user home dir
USERHOME=~/
# get script path # get script path
DIR="${BASH_SOURCE%/*}" DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" || "$DIR" == '.' ]]; then DIR="$PWD"; fi if [[ ! -d "$DIR" || "$DIR" == '.' ]]; then DIR="$PWD"; fi
@ -29,14 +31,15 @@ if [[ ! -d "$DIR" || "$DIR" == '.' ]]; then DIR="$PWD"; fi
# load functions # load functions
. "$DIR/incl.sh" . "$DIR/incl.sh"
# we move out of the script folder # got to script folder
cd "$DIR" cd "$DIR"
cd ../ # set Base Dir
BASEDIR="$PWD"
# get random folder name to avoid conflict # get random folder name to avoid conflict
newFolder=$(getRandom) newFolder=$(getRandom)
# set this repo location # set this repo location
tmpFolder="$PWD/T3MPR3P0_$newFolder" tmpFolder="$USERHOME/T3MPR3P0_$newFolder"
# create tmp folder # create tmp folder
if [ ! -d "$tmpFolder" ] if [ ! -d "$tmpFolder" ]
then then
@ -45,23 +48,26 @@ fi
# DB file # DB file
databasesFileName="databases" databasesFileName="databases"
databaseBuilder="$DIR/$databasesFileName" databaseBuilder="$BASEDIR/$databasesFileName"
# check if file exist # check if file exist
if [ ! -f "$databaseBuilder" ] if [ ! -f "$databaseBuilder" ]
then then
echo 'No databases.txt found' echo 'No databases filefound'
exit 1 exit 1
fi fi
# folder names # folder names
foldersFileName="folders" foldersFileName="folders"
folderBuilder="$DIR/$foldersFileName" folderBuilder="$BASEDIR/$foldersFileName"
# check if file exist # check if file exist
if [ ! -f "$folderBuilder" ] if [ ! -f "$folderBuilder" ]
then then
echo 'No folders.txt found' echo 'No folders folder found'
exit 1 exit 1
fi fi
# we move to user folder
cd "$USERHOME"
# run main # run main
. "$DIR/main.sh" . "$BASEDIR/main.sh"