1
0
mirror of https://github.com/Llewellynvdm/Backup-System.git synced 2024-12-11 16:43:31 +00:00

Started the work of setting the stage for reverting back-up. Also fixed the zip path issue.

This commit is contained in:
Llewellyn van der Merwe 2018-07-11 02:56:25 +02:00
parent 11d0e8582a
commit bcc5bcd5fc
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
7 changed files with 116 additions and 24 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
databases
folders
config.sh
dropboxpath

View File

@ -27,7 +27,7 @@ Make sure the run file is executable
$ chmod +x run.sh
```
## Automated Option (guided setup option)
## Auto Setup Option
Just run :)
@ -35,7 +35,7 @@ Just run :)
$ ./run.sh
```
## Manual Option
## Manual Setup Option
Copy __config.txt__ to __config.sh__ and update the values in the file.
@ -61,6 +61,14 @@ Run the script
$ ./run.sh
```
## Fetch Backup and Restore
Either revert to previous backup (restore) or to do a new deployment.
```bash
$ ./run.sh -r
```
## Tested Environments
* GNU Linux

View File

@ -18,11 +18,11 @@ REMOTESSH="user@yourserver.com"
DROPBOX="/home/path/to/Dropbox-Uploader/dropbox_uploader.sh"
# PATH DETAILS
REMOTEDBPATH="your_db_path/"
REMOTEWEBPATH="your_website_path/"
REMOTEDBPATH="db_path/"
REMOTEWEBPATH="website_path/"
## WEBSITE BACKUP TYPE (1 = PER/FILE || 2 = ZIPPED)
WEBBACKUPTYPE=1
WEBBACKUPTYPE=2
## 0 = no date | 1 = year | 2 = year-month | 3 = your-month-day | 4 = your-month-day:time # For DB file name
USEDATE=0
USEDATE=1

View File

@ -101,8 +101,12 @@ function moveWEB () {
else
FILE="$2.zip"
fi
# go to local folder
cd "${localFolder}"
# zip the website
zip -r -q "${FILE}" "${localFolder}"
zip -r -q "${tmpFolder}/${FILE}" *
# we move to tmp folder
cd "$tmpFolder"
# set the paths
PaTh="${FILE}"
remotePaTh="${REMOTEWEBPATH}${FILE}"

43
main.sh
View File

@ -33,10 +33,20 @@ MOVEWEBWHAT='None'
### MAIN ###
function main () {
# backup the databases now
backupDB
# backup the websites now
backupWEB
# do backup
if [ "$REVERT" -ne 1 ]; then
# backup the databases now
backupDB
# backup the websites now
backupWEB
else
# revert the databases now
revertDB
# revert the websites now
revertWEB
# force remove tmp
rmTmp 4
fi
}
function rmTmp () {
@ -47,10 +57,13 @@ function rmTmp () {
elif [ "$1" -eq "2" ]; then
#confirm we are done
BACKUPWEBDONE=1
elif [ "$1" -eq "4" ]; then
# now force remove tmp
rmFolder "$tmpFolder"
fi
# only if both are done
if [ "$BACKUPWEBDONE" -eq "1" ] && [ "$BACKUPDBDONE" -eq "1" ]; then
# now remove the local file
# now remove tmp
rmFolder "$tmpFolder"
fi
}
@ -100,6 +113,26 @@ function backupWEB () {
rmTmp 2
}
# function to revert DB's
function revertDB () {
while IFS=$'\t' read -r -a database
do
[[ "$database" =~ ^#.*$ ]] && continue
# the local database details
# echo "${database[0]}" "${database[1]}" "${database[2]}" "${database[3]}" "${database[4]}"
done < $databaseBuilder
}
# function to revert WEB folders
function revertWEB () {
while IFS=$'\t' read -r -a foalder
do
[[ "$foalder" =~ ^#.*$ ]] && continue
# the local folder & remote file name
# echo "${foalder[0]}" "${foalder[1]}"
done < $folderBuilder
}
# run the main only at the end!
main

15
run.sh
View File

@ -21,6 +21,8 @@
# user home dir
USERHOME=~/
# switch to revert
REVERT=0
# get script path
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" || "$DIR" == '.' ]]; then DIR="$PWD"; fi
@ -54,7 +56,7 @@ tmpFolder="${USERHOME}T3MPR3P0_${newFolder}"
# create tmp folder
if [ ! -d "$tmpFolder" ]
then
mkdir -p "$tmpFolder"
mkdir -p "$tmpFolder"
fi
# DB file
@ -78,5 +80,16 @@ fi
# we move to user folder
cd "$USERHOME"
#Look for optional config parameter
while getopts ":r" opt; do
case $opt in
r)
REVERT=1
;;
esac
done
# run main
. "$BASEDIR/main.sh"

View File

@ -23,17 +23,35 @@
function runSetupConfig () {
# get backup type
echo -ne "\n Select Backup Type\n"
echo -ne " 1 = Remote Server\n"
echo -ne " 1 = Remote Server (default)\n"
echo -ne " 2 = Dropbox\n"
echo -ne " # Make your selection [1/2]: "
read -r INPUT_BACKUPTYPE
# set default
INPUT_BACKUPTYPE=${INPUT_BACKUPTYPE:-1}
# get the details for the backup type
if [ "$INPUT_BACKUPTYPE" -eq "2" ]; then
# get dropbox uploader path
echo -ne "\n Set the Path to the Dropbox Uploader File\n"
echo -ne " Use https://github.com/andreafabrizi/Dropbox-Uploader\n"
echo -ne " # Example (/home/path/to/Dropbox-Uploader/dropbox_uploader.sh): "
read -r INPUT_DROPBOX
# check if another should be added
echo -ne "\n Do you have the path to the Dropbox Uploader File? [y/N]: "
read -r answer
if [[ $answer != "y" ]]; then
echo -ne "\n YOU MUST GET THE PATH TO THE DROPBOX UPLOADER FILE!\n" ;
echo -ne " For more help https://github.com/andreafabrizi/Dropbox-Uploader\n"
# start again
exit 1
else
# get dropbox uploader path
echo -ne "\n Set the Path to the Dropbox Uploader File\n"
echo -ne " # Example (/home/path/to/Dropbox-Uploader/dropbox_uploader.sh): "
read -r INPUT_DROPBOX
# check that we have a string
if [ ! ${#INPUT_DROPBOX} -ge 2 ]; then
echo -ne "\n YOU MUST GET THE PATH TO THE DROPBOX UPLOADER FILE!\n" ;
echo -ne " For more help https://github.com/andreafabrizi/Dropbox-Uploader\n"
# start again
exit 1
fi
fi
# set default remote server details
INPUT_REMOTESSH="user@yourserver.com"
else
@ -41,32 +59,47 @@ function runSetupConfig () {
echo -ne "\n Set the Remote Server Details\n"
echo -ne " # Example (user@yourserver.com): "
read -r INPUT_REMOTESSH
# check that we have a string
if [ ! ${#INPUT_REMOTESSH} -ge 2 ]; then
echo -ne "\n YOU MUST GIVE THE REMOTE SERVER DETAILS!\n" ;
echo -ne " # Example (user@yourserver.com)\n"
# start again
exit 1
fi
# set default dropbox details
INPUT_DROPBOX="/media/host/root/Dropbox-Uploader/dropbox_uploader.sh"
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 " # Example (your_db_path/): "
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 " # Example (your_website_path/): "
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\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\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}
# now add it all to the config file
echo "#!/bin/bash" > "$1"