Added Dropbox support, and the option to zip the website backup

This commit is contained in:
Llewellyn van der Merwe 2018-07-05 05:27:01 +02:00
parent 0bcf85a890
commit 8e59f87023
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
6 changed files with 132 additions and 12 deletions

View File

@ -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:

View File

@ -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

38
incl.sh
View File

@ -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 () {

15
main.sh
View File

@ -10,7 +10,7 @@
# |_|
#/-------------------------------------------------------------------------------------------------------------------------------/
#
# @version 1.0.0
# @version 1.0.0
# @build 9th May, 2017
# @package Backup System
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
@ -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!

0
run.sh Normal file → Executable file
View File

72
setup.sh Normal file
View File

@ -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 <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
#
#/-----------------------------------------------------------------------------------------------------------------------------/
### 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