forked from Llewellynvdm/Backup-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
164 lines (148 loc) · 4.68 KB
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
#/--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
# __ __ _ _____ _ _ __ __ _ _ _
# \ \ / / | | | __ \ | | | | | \/ | | | | | | |
# \ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
# \ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
# \ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
# \/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
# | |
# |_|
#/-------------------------------------------------------------------------------------------------------------------------------/
#
# @version 2.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
#
#/-----------------------------------------------------------------------------------------------------------------------------/
#confirm we are done with database backup
if [ "$BACKUPDATABASE" -eq "1" ]; then
BACKUPDBDONE=0
else
BACKUPDBDONE=1
fi
#confirm we are done with website backup
if [ "$BACKUPWEBSITES" -eq "1" ]; then
BACKUPWEBDONE=0
else
BACKUPWEBDONE=1
fi
# some error handle
MOVEDBRESULT=0
MOVEWEBRESULT=0
# for global messages
MOVEDBWHAT='None'
MOVEWEBWHAT='None'
### MAIN ###
function main () {
# do backup
if [ "$REVERT" -ne 1 ]; then
# backup the databases now
if [ "$BACKUPDATABASE" -eq "1" ]; then
backupDB
fi
# backup the websites now
if [ "$BACKUPWEBSITES" -eq "1" ]; then
backupWEB
fi
else
# revert the databases now
if [ "$BACKUPDATABASE" -eq "1" ]; then
revertDB
fi
# revert the websites now
if [ "$BACKUPWEBSITES" -eq "1" ]; then
revertWEB
fi
# force remove tmp
rmTmp 4
fi
}
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
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 tmp
rmFolder "$tmpFolder"
fi
}
# 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"
# check if move was success
checkMove 1
done < $databaseBuilder
# 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
# try to remove tmp
rmTmp 1
}
# 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]}"
# check if move was success
checkMove 2
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
# try to remove tmp
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
echo "Soon we will add this feature in its full.";
}
# 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
echo "Soon we will add this feature in its full.";
}
# run the main only at the end!
main
# try again
rmTmp 3
# We are done
exit 0