forked from BCDevOps/backup-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·140 lines (125 loc) · 3.67 KB
/
backup.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
#!/bin/bash
# ======================================================================================
# Imports
# --------------------------------------------------------------------------------------
. ./backup.usage # Usage information
. ./backup.logging # Logging functions
. ./backup.config.utils # Configuration functions
. ./backup.container.utils # Container Utility Functions
. ./backup.ftp # FTP Support functions
. ./backup.misc.utils # General Utility Functions
. ./backup.file.utils # File Utility Functions
. ./backup.utils # Primary Database Backup and Restore Functions
. ./backup.server.utils # Backup Server Utility Functions
. ./backup.settings # Default Settings
# ======================================================================================
# ======================================================================================
# Initialization:
# --------------------------------------------------------------------------------------
trap shutDown EXIT TERM
# Load database plug-in based on the container type ...
. ./backup.${CONTAINER_TYPE}.plugin > /dev/null 2>&1
if [[ ${?} != 0 ]]; then
echoRed "backup.${CONTAINER_TYPE}.plugin not found."
# Default to null plugin.
export CONTAINER_TYPE=${UNKNOWN_DB}
. ./backup.${CONTAINER_TYPE}.plugin > /dev/null 2>&1
fi
while getopts nclr:v:f:1spha: FLAG; do
case $FLAG in
n)
# Allow null database plugin ...
# Without this flag loading the null plugin is considered a configuration error.
# The null plugin can be used for testing.
export _allowNullPlugin=1
;;
c)
echoBlue "\nListing configuration settings ..."
listSettings
exit 0
;;
l)
listExistingBackups ${ROOT_BACKUP_DIR}
exit 0
;;
r)
# Trigger restore mode ...
export _restoreDatabase=${OPTARG}
;;
v)
# Trigger verify mode ...
export _verifyBackup=${OPTARG}
;;
f)
# Optionally specify the backup file to verify or restore from ...
export _fromBackup=${OPTARG}
;;
1)
export RUN_ONCE=1
;;
s)
export SCHEDULED_RUN=1
;;
p)
export RUN_PRUNE=1
;;
a)
export _adminPassword=${OPTARG}
;;
h)
usage
;;
\?)
echo -e \\n"Invalid option: -${OPTARG}"\\n
usage
;;
esac
done
shift $((OPTIND-1))
# ======================================================================================
# ======================================================================================
# Main Script
# --------------------------------------------------------------------------------------
case $(getMode) in
${ONCE})
runBackups
echoGreen "Single backup run complete.\n"
;;
${SCHEDULED})
runBackups
echoGreen "Scheduled backup run complete.\n"
;;
${RESTORE})
unset restoreFlags
if isScripted; then
restoreFlags="-q"
fi
if validateOperation "${_restoreDatabase}" "${RESTORE}"; then
restoreDatabase ${restoreFlags} "${_restoreDatabase}" "${_fromBackup}"
fi
;;
${VERIFY})
verifyBackups "${_verifyBackup}" "${_fromBackup}"
;;
${SCHEDULED_VERIFY})
verifyBackups -q "${_verifyBackup}" "${_fromBackup}"
;;
${CRON})
startCron
;;
${LEGACY})
startLegacy
;;
${PRUNE})
prune
;;
${ERROR})
echoRed "A configuration error has occurred, review the details above."
usage
;;
*)
echoYellow "Unrecognized operational mode; ${_mode}"
usage
;;
esac
# ======================================================================================