Added an auto setup guide to run
This commit is contained in:
parent
4d992b06fa
commit
be01e19c56
55
README.md
55
README.md
|
@ -6,6 +6,7 @@ The Bash scripts used to backup database and folders on a server
|
||||||
|
|
||||||
* Cross platform
|
* Cross platform
|
||||||
* Fast and effective backups
|
* Fast and effective backups
|
||||||
|
* Backup to Dropbox
|
||||||
* Ability to track changes
|
* Ability to track changes
|
||||||
* Historical records
|
* Historical records
|
||||||
* Preserve the folder structure
|
* Preserve the folder structure
|
||||||
|
@ -16,34 +17,42 @@ The Bash scripts used to backup database and folders on a server
|
||||||
Clone Repository
|
Clone Repository
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ git clone https://github.com/vdm-io/Backup-System.git system-backup
|
$ git clone https://github.com/vdm-io/Backup-System.git Backup-System
|
||||||
```
|
```
|
||||||
|
|
||||||
Rename __config.txt__ to __config.sh__ and update the values in the file.
|
Make sure all the run file is executable
|
||||||
|
|
||||||
```bash
|
|
||||||
$ mv config.txt config.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Rename __folders.txt__ to __folders__ and update the values in the file.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ mv folders.txt folders
|
|
||||||
```
|
|
||||||
|
|
||||||
Rename __databases.txt__ to __databases__ and update the values in the file.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ mv databases.txt databases
|
|
||||||
```
|
|
||||||
|
|
||||||
Make sure all the needed files are executable
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
$ cd Backup-System/
|
||||||
$ chmod +x run.sh
|
$ chmod +x run.sh
|
||||||
$ chmod +x main.sh
|
```
|
||||||
$ chmod +x incl.sh
|
|
||||||
$ chmod +x config.sh
|
## Automated Option (guided setup option)
|
||||||
|
|
||||||
|
Just run :)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ./run.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Manual Option
|
||||||
|
|
||||||
|
Copy __config.txt__ to __config.sh__ and update the values in the file.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cp config.txt config.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy __folders.txt__ to __folders__ and update the values in the file.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cp folders.txt folders
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy __databases.txt__ to __databases__ and update the values in the file.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cp databases.txt databases
|
||||||
```
|
```
|
||||||
|
|
||||||
Run the script
|
Run the script
|
||||||
|
|
2
incl.sh
2
incl.sh
|
@ -10,7 +10,7 @@
|
||||||
# |_|
|
# |_|
|
||||||
#/-------------------------------------------------------------------------------------------------------------------------------/
|
#/-------------------------------------------------------------------------------------------------------------------------------/
|
||||||
#
|
#
|
||||||
# @version 1.0.0
|
# @version 2.0.0
|
||||||
# @build 9th May, 2017
|
# @build 9th May, 2017
|
||||||
# @package Backup System
|
# @package Backup System
|
||||||
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
||||||
|
|
2
main.sh
2
main.sh
|
@ -10,7 +10,7 @@
|
||||||
# |_|
|
# |_|
|
||||||
#/-------------------------------------------------------------------------------------------------------------------------------/
|
#/-------------------------------------------------------------------------------------------------------------------------------/
|
||||||
#
|
#
|
||||||
# @version 1.0.0
|
# @version 2.0.0
|
||||||
# @build 9th May, 2017
|
# @build 9th May, 2017
|
||||||
# @package Backup System
|
# @package Backup System
|
||||||
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
||||||
|
|
29
run.sh
29
run.sh
|
@ -10,7 +10,7 @@
|
||||||
# |_|
|
# |_|
|
||||||
#/-------------------------------------------------------------------------------------------------------------------------------/
|
#/-------------------------------------------------------------------------------------------------------------------------------/
|
||||||
#
|
#
|
||||||
# @version 1.0.0
|
# @version 2.0.0
|
||||||
# @build 9th May, 2017
|
# @build 9th May, 2017
|
||||||
# @package Backup System
|
# @package Backup System
|
||||||
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
||||||
|
@ -25,6 +25,17 @@ USERHOME=~/
|
||||||
DIR="${BASH_SOURCE%/*}"
|
DIR="${BASH_SOURCE%/*}"
|
||||||
if [[ ! -d "$DIR" || "$DIR" == '.' ]]; then DIR="$PWD"; fi
|
if [[ ! -d "$DIR" || "$DIR" == '.' ]]; then DIR="$PWD"; fi
|
||||||
|
|
||||||
|
# load setup incase
|
||||||
|
. "$DIR/setup.sh"
|
||||||
|
|
||||||
|
# config file
|
||||||
|
DIRconfig="$DIR/config.sh"
|
||||||
|
# check if file exist
|
||||||
|
if [ ! -f "$DIRconfig" ]
|
||||||
|
then
|
||||||
|
runSetup 1 "$DIRconfig"
|
||||||
|
fi
|
||||||
|
|
||||||
# load configuration file
|
# load configuration file
|
||||||
. "$DIR/config.sh"
|
. "$DIR/config.sh"
|
||||||
|
|
||||||
|
@ -41,10 +52,10 @@ newFolder=$(getRandom)
|
||||||
# set this repo location
|
# set this repo location
|
||||||
tmpFolder="$USERHOME/T3MPR3P0_$newFolder"
|
tmpFolder="$USERHOME/T3MPR3P0_$newFolder"
|
||||||
# create tmp folder
|
# create tmp folder
|
||||||
if [ ! -d "$tmpFolder" ]
|
#if [ ! -d "$tmpFolder" ]
|
||||||
then
|
#then
|
||||||
mkdir -p "$tmpFolder"
|
# mkdir -p "$tmpFolder"
|
||||||
fi
|
#fi
|
||||||
|
|
||||||
# DB file
|
# DB file
|
||||||
databasesFileName="databases"
|
databasesFileName="databases"
|
||||||
|
@ -52,18 +63,16 @@ databaseBuilder="$BASEDIR/$databasesFileName"
|
||||||
# check if file exist
|
# check if file exist
|
||||||
if [ ! -f "$databaseBuilder" ]
|
if [ ! -f "$databaseBuilder" ]
|
||||||
then
|
then
|
||||||
echo 'No databases filefound'
|
runSetup 2 "$databaseBuilder"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# folder names
|
# folder names
|
||||||
foldersFileName="folders"
|
foldersFileName="folders"
|
||||||
folderBuilder="$BASEDIR/$foldersFileName"
|
folderBuilder="$BASEDIR/$foldersFileName"
|
||||||
# check if file exist
|
# check if file exist
|
||||||
if [ ! -f "$folderBuilder" ]
|
if [ ! -f "$folderBuilder" ]
|
||||||
then
|
then
|
||||||
echo 'No folders folder found'
|
runSetup 3 "$folderBuilder"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# we move to user folder
|
# we move to user folder
|
||||||
|
|
263
setup.sh
263
setup.sh
|
@ -10,7 +10,7 @@
|
||||||
# |_|
|
# |_|
|
||||||
#/-------------------------------------------------------------------------------------------------------------------------------/
|
#/-------------------------------------------------------------------------------------------------------------------------------/
|
||||||
#
|
#
|
||||||
# @version 1.0.0
|
# @version 2.0.0
|
||||||
# @build 9th May, 2017
|
# @build 9th May, 2017
|
||||||
# @package Backup System
|
# @package Backup System
|
||||||
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
# @author Llewellyn van der Merwe <https://github.com/Llewellynvdm>
|
||||||
|
@ -19,54 +19,225 @@
|
||||||
#
|
#
|
||||||
#/-----------------------------------------------------------------------------------------------------------------------------/
|
#/-----------------------------------------------------------------------------------------------------------------------------/
|
||||||
|
|
||||||
### MAIN ###
|
### setup config file ###
|
||||||
function main () {
|
function runSetupConfig () {
|
||||||
# backup the databases now
|
# get backup type
|
||||||
backupDB &
|
echo -ne "\n Select Backup Type\n"
|
||||||
# backup the websites now
|
echo -ne " 1 = Remote Server\n"
|
||||||
backupWEB
|
echo -ne " 2 = Dropbox\n"
|
||||||
|
echo -ne " # Make your selection [1/2]: "
|
||||||
|
read -r INPUT_BACKUPTYPE
|
||||||
|
# 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
|
||||||
|
# set default remote server details
|
||||||
|
INPUT_REMOTESSH="user@yourserver.com"
|
||||||
|
else
|
||||||
|
# get remote server details
|
||||||
|
echo -ne "\n Set the Remote Server Details\n"
|
||||||
|
echo -ne " # Example (user@yourserver.com): "
|
||||||
|
read -r INPUT_REMOTESSH
|
||||||
|
# set default dropbox details
|
||||||
|
INPUT_DROPBOX="/media/host/root/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/): "
|
||||||
|
read -r INPUT_REMOTEDBPATH
|
||||||
|
# get the remote website backup paths
|
||||||
|
echo -ne "\n Set Remote Backup Path for Website Backups\n"
|
||||||
|
echo -ne " # Example (your_website_path/): "
|
||||||
|
read -r INPUT_REMOTEWEBPATH
|
||||||
|
# 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 " # Make your selection [1/2]: "
|
||||||
|
read -r INPUT_WEBBACKUPTYPE
|
||||||
|
# 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 " 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
|
||||||
|
|
||||||
|
# now add it all to the config file
|
||||||
|
echo "#!/bin/bash" > "$1"
|
||||||
|
echo "" >> "$1"
|
||||||
|
echo "##############################################################" >> "$1"
|
||||||
|
echo "############## ##########" >> "$1"
|
||||||
|
echo "############## CONFIG ##########" >> "$1"
|
||||||
|
echo "############## ##########" >> "$1"
|
||||||
|
echo "##############################################################" >> "$1"
|
||||||
|
echo "#### just update these to point to your server ###" >> "$1"
|
||||||
|
echo "##############################################################" >> "$1"
|
||||||
|
echo "" >> "$1"
|
||||||
|
echo "## BACKUP TYPE (1 = REMOTE SERVER || 2 = DROPBOX)" >> "$1"
|
||||||
|
echo "BACKUPTYPE=${INPUT_BACKUPTYPE}" >> "$1"
|
||||||
|
echo "" >> "$1"
|
||||||
|
echo "## REMOTE SERVER DETAILS (1)" >> "$1"
|
||||||
|
echo "REMOTESSH=\"${INPUT_REMOTESSH}\"" >> "$1"
|
||||||
|
echo "" >> "$1"
|
||||||
|
echo "## DROPBOX DETAILS (2) (get it from https://github.com/andreafabrizi/Dropbox-Uploader)" >> "$1"
|
||||||
|
echo "DROPBOX=\"${INPUT_DROPBOX}\"" >> "$1"
|
||||||
|
echo "" >> "$1"
|
||||||
|
echo "# PATH DETAILS" >> "$1"
|
||||||
|
echo "REMOTEDBPATH=\"${INPUT_REMOTEDBPATH}\"" >> "$1"
|
||||||
|
echo "REMOTEWEBPATH=\"${INPUT_REMOTEWEBPATH}\"" >> "$1"
|
||||||
|
echo "" >> "$1"
|
||||||
|
echo "## WEBSITE BACKUP TYPE (1 = PER/FILE || 2 = ZIPPED)" >> "$1"
|
||||||
|
echo "WEBBACKUPTYPE=\"${INPUT_WEBBACKUPTYPE}\"" >> "$1"
|
||||||
|
echo "" >> "$1"
|
||||||
|
echo "## 0 = no date | 1 = year | 2 = year-month | 3 = your-month-day | 4 = your-month-day:time # For DB file name" >> "$1"
|
||||||
|
echo "USEDATE=\"${INPUT_USEDATE}\"" >> "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to backup all DB's
|
### setup databases file ###
|
||||||
function backupDB () {
|
function runSetupDBs () {
|
||||||
while IFS=$'\t' read -r -a database
|
# start building the database details
|
||||||
|
echo "# DBSERVER FILENAME DATABASE USER PASS" > "$1"
|
||||||
|
# start Database tutorial
|
||||||
|
echo -ne "\n RUNNING DATABASE SETUP\n"
|
||||||
|
# set checker to get more
|
||||||
|
GETTING=1
|
||||||
|
while [ "$GETTING" -eq "1" ]
|
||||||
do
|
do
|
||||||
[[ "$database" =~ ^#.*$ ]] && continue
|
# get the Database IP/Domain
|
||||||
# zip the database
|
echo -ne "\n Set the Database IP/Domain\n"
|
||||||
DBFILE=$(zipDB "${database[0]}" "${database[1]}" "${database[2]}" "${database[3]}" "${database[4]}")
|
read -e -p " # Example (127.0.0.1 | localhost): " -i "127.0.0.1" INPUT_DBSERVER
|
||||||
# move to backup server
|
# check that we have a string
|
||||||
moveDB "$DBFILE"
|
if [ ! ${#INPUT_DBSERVER} -ge 2 ]; then
|
||||||
done < $databaseBuilder
|
echo -ne "\n YOU MUST ADD A DATABASE IP/DOMAIN!\n\n" ;
|
||||||
|
# remove the file
|
||||||
# now remove the local file
|
rm "$1"
|
||||||
rmTmpFolder "$tmpFolder"
|
# start again
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# get the File Name
|
||||||
|
echo -ne "\n Set the File Name for the Database Package\n"
|
||||||
|
echo -ne " # Example (filename): "
|
||||||
|
read -r INPUT_FILENAME
|
||||||
|
# check that we have a string
|
||||||
|
if [ ! ${#INPUT_FILENAME} -ge 2 ]; then
|
||||||
|
echo -ne "\n YOU MUST ADD A FILE NAME!\n\n" ;
|
||||||
|
# remove the file
|
||||||
|
rm "$1"
|
||||||
|
# start again
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# get the Database Name
|
||||||
|
echo -ne "\n Set the Database Name\n"
|
||||||
|
echo -ne " # Example (database_name): "
|
||||||
|
read -r INPUT_DATABASE
|
||||||
|
# check that we have a string
|
||||||
|
if [ ! ${#INPUT_DATABASE} -ge 2 ]; then
|
||||||
|
echo -ne "\n YOU MUST ADD A DATABASE NAME!\n\n" ;
|
||||||
|
# remove the file
|
||||||
|
rm "$1"
|
||||||
|
# start again
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# get the Database User Name
|
||||||
|
echo -ne "\n Set the Database User Name\n"
|
||||||
|
echo -ne " # Example (database_user): "
|
||||||
|
read -r INPUT_USER
|
||||||
|
# check that we have a string
|
||||||
|
if [ ! ${#INPUT_USER} -ge 2 ]; then
|
||||||
|
echo -ne "\n YOU MUST ADD A DATABASE USER NAME!\n\n" ;
|
||||||
|
# remove the file
|
||||||
|
rm "$1"
|
||||||
|
# start again
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# get the Database User Password
|
||||||
|
echo -ne "\n Set the Database User Password\n"
|
||||||
|
echo -ne " # Example (realy..): "
|
||||||
|
read -s INPUT_PASSWORD
|
||||||
|
# check that we have a string
|
||||||
|
if [ ! ${#INPUT_PASSWORD} -ge 2 ]; then
|
||||||
|
echo -ne "\n YOU MUST ADD A DATABASE USER PASSWORD!\n\n" ;
|
||||||
|
# remove the file
|
||||||
|
rm "$1"
|
||||||
|
# start again
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# add to the file
|
||||||
|
echo "${INPUT_DBSERVER} ${INPUT_FILENAME} ${INPUT_DATABASE} ${INPUT_USER} ${INPUT_PASSWORD}" >> "$1"
|
||||||
|
# check if another should be added
|
||||||
|
echo ""
|
||||||
|
echo -ne "\n Would you like to add another database? [y/N]: "
|
||||||
|
read -r answer
|
||||||
|
if [[ $answer != "y" ]]; then
|
||||||
|
# end the loop
|
||||||
|
GETTING=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# start fresh
|
### setup folders file ###
|
||||||
cd "$USERHOME"
|
function runSetupFolders () {
|
||||||
# GO To remote server and do house cleaning
|
# start building the website folder details
|
||||||
if [ "$BACKUPTYPE" -eq "1" ]; then
|
echo "# local_site_path remote_site_folder_name" > "$1"
|
||||||
ssh -tt -p '22' "$REMOTESSH" "$(typeset -f); remoteHouseCleaning $REMOTEDBPATH"
|
# start Folder tutorial
|
||||||
|
echo -ne "\n RUNNING FOLDER SETUP\n"
|
||||||
|
# set checker to get more
|
||||||
|
GETTING=1
|
||||||
|
while [ "$GETTING" -eq "1" ]
|
||||||
|
do
|
||||||
|
# get local folder path path
|
||||||
|
echo -ne "\n Set the Local Folder Path\n"
|
||||||
|
echo -ne " # Example (/home/username/): "
|
||||||
|
read -r INPUT_LOCAL_PATH
|
||||||
|
# check that we have a local path
|
||||||
|
if [ ! -d "$INPUT_LOCAL_PATH" ]; then
|
||||||
|
echo -ne "\n YOU MUST ADD A LOCAL PATH!\n\n" ;
|
||||||
|
# remove the file
|
||||||
|
rm "$1"
|
||||||
|
# start again
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# get local folder path path
|
||||||
|
echo -ne "\n Set the Remote Folder Path\n"
|
||||||
|
echo -ne " # Example (username): "
|
||||||
|
read -r INPUT_REMOTE_PATH
|
||||||
|
# check that we have a string
|
||||||
|
if [ ! ${#INPUT_REMOTE_PATH} -ge 2 ]; then
|
||||||
|
echo -ne "\n YOU MUST ADD A REMOTE PATH!\n\n" ;
|
||||||
|
# remove the file
|
||||||
|
rm "$1"
|
||||||
|
# start again
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# add to the file
|
||||||
|
echo "${INPUT_LOCAL_PATH} ${INPUT_REMOTE_PATH}" >> "$1"
|
||||||
|
# check if another should be added
|
||||||
|
echo ""
|
||||||
|
echo -ne "\n Would you like to add another folder? [y/N]: "
|
||||||
|
read -r answer
|
||||||
|
if [[ $answer != "y" ]]; then
|
||||||
|
# end the loop
|
||||||
|
GETTING=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
### MAIN SETUP ###
|
||||||
|
function runSetup () {
|
||||||
|
# if setup config
|
||||||
|
if [ "$1" -eq "1" ]; then
|
||||||
|
runSetupConfig "$2"
|
||||||
|
# if setup database
|
||||||
|
elif [ "$1" -eq "2" ]; then
|
||||||
|
runSetupDBs "$2"
|
||||||
|
# if setup folders
|
||||||
|
elif [ "$1" -eq "3" ]; then
|
||||||
|
runSetupFolders "$2"
|
||||||
fi
|
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
|
|
||||||
|
|
Loading…
Reference in New Issue