-
Notifications
You must be signed in to change notification settings - Fork 0
/
borg_wrapper.sh
executable file
·264 lines (232 loc) · 5.53 KB
/
borg_wrapper.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
# Base Variables
version="v1.1"
# READ DIR
t_dir=$(dirname $0)
# source the functions
for file in ${t_dir}/functions/* ; do
source ${file}
done
#Loglevel for logfile (1 CRIT, 2 DEBUG, 3INFO)
bw_loglevel="1"
bw_log "3" "Borg wrapper starting"
# getting the args
while (( "$#" )); do
# debug
# echo "--> $1 ($2)"
case $1 in
### READ PROJECT
-p|--project)
if [[ -z "$2" ]] ; then
bw_log "1" "Missing project name - exiting"
exit 1
# start of implementation for ALL Keyword
elif [[ "$2" == "all" ]] ; then
bw_log "3" "you hit a special keyword !! - congrats - running through all projects (excluding smaple)"
bw_log "3" "no, just kidding - just listing them ;)"
for t_project in `ls ${t_dir}/projects/` ; do
if [[ -z "$(echo ${t_project} | egrep "sample.bw.sh|global.sample.bw.sh|global.bw.sh")" ]] ; then
# source ${t_project}
echo "> $t_project"
#$0 --project ${t_project} --"${bw_action}"
fi
done
exit 0
# end of implementation for ALL Keyword
else
bw_o_project=$2
if [[ -f "${t_dir}/projects/${bw_o_project}.bw.sh" ]] ; then
source ${t_dir}/projects/${bw_o_project}.bw.sh
elif [[ -f ${bw_o_project} ]] ; then
source ${bw_o_project}
else
bw_log "1" "could not find projectfile ${bw_o_project} - exiting"
exit 1
fi
if [[ -f "${t_dir}/projects/global.bw.sh" ]] ; then
source ${t_dir}/projects/global.bw.sh
else
bw_log "3" "no global config file projects/global.bw.sh found ... "
fi
fi
shift
;;
### ACTIONS
-b|--backup)
check_action
bw_action="backup"
bw_log "3" "selected action: ${bw_action}"
;;
-C|--check|-v|--verify)
check_action
bw_action="check"
bw_log "3" "selected action: ${bw_action}"
if [[ -z "$2" ]] ; then
bw_log "0" "Missing backup artefact - exiting"
exit 1
else
f-bw_checkartefactoption "$2"
bw_o_checkbck=$2
fi
shift
;;
--cron)
check_action
bw_action="cron"
bw_log "3" "selected action: ${bw_action}"
;;
--icinga)
check_action
bw_action="icinga"
bw_log "3" "selected action: ${bw_action}"
if [[ -z "$2" ]] && [[ -z "${bw_icingaoptions}" ]] ; then
bw_log "1" "Missing icinga vlaues warning,critical (cli or conf)- exiting"
exit 1
elif [[ -z "$2" ]] && [[ ! -z "${bw_icingaoptions}" ]] ; then
bw_o_icingavalues=${bw_icingaoptions}
else
bw_o_icingavalues="${2}"
shift
fi
;;
-i|--init)
check_action
bw_action="init"
bw_log "3" "selected action: ${bw_action}"
;;
-I|--info)
check_action
bw_action="info"
bw_log "3" "selected action: ${bw_action}"
if [[ -z "$2" ]] ; then
bw_log "1" "Missing backup artefact - exiting"
exit 1
else
f-bw_checkartefactoption "$2"
bw_o_infobck=$2
fi
shift
;;
-l|--list)
check_action
bw_action="list"
bw_log "3" "selected action: ${bw_action}"
;;
-m|--mount)
check_action
bw_action="mount"
bw_log "3" "selected action: ${bw_action}"
if [[ -z "$2" ]] ; then
bw_log"1" "Missing backup artefact - exiting"
exit 1
else
f-bw_checkartefactoption "$2"
bw_o_mountbck=$2
fi
if [[ -z "$3" ]] ; then
bw_log"1" "Missing backup artefact - exiting"
exit 1
else
f-bw_checkdiroption "$3"
bw_o_mountdir=$3
fi
shift
shift
;;
-P|--prune)
check_action
bw_action="prune"
bw_log "3" "selected action: ${bw_action}"
;;
-s|--shell)
check_action
bw_action="shell"
bw_log "3" "selected action: ${bw_action}"
;;
### OPTIONS
# DEbugging (ways to late, please fix me"
-d)
bw_log "2" "Sent debugging flag on CLI"
bw_o_debug="--debug"
bw_loglevel="3"
;;
# HElp
-h|--help|*)i
f-bw_help
exit 0
;;
esac
shift
done
bw_log "3" "successfully parsed the CLI - params"
if [[ -z "${bw_action}" ]] ; then
f-bw_help
exit 0
fi
### binaries
#borg_bin="/usr/bin/borg"
f-bw_checkborginstallation
#borg_bin="${borg_bin} ${bw_additional_options}"
# PRoject Variable check
f-bw_checkprojectconfig
bw_log "3" "exporting BORG_PAASSPHRASE with password"
export BORG_PASSPHRASE="${bw_password}"
#### Run triggered Actions
case ${bw_action} in
backup)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_backup
bw_log "3" "finished ACTION: ${bw_action}"
;;
check)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_check ${bw_o_checkbck}
bw_log "3" "finished ACTION: ${bw_action}"
;;
cron)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_cron ${bw_o_checkbck}
bw_log "3" "finished ACTION: ${bw_action}"
;;
icinga)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_icinga ${bw_o_icingavalues}
bw_log "3" "finished ACTION: ${bw_action}"
;;
init)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_init
bw_log "3" "finished ACTION: ${bw_action}"
;;
info)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_info ${bw_o_infobck}
bw_log "3" "finished ACTION: ${bw_action}"
;;
list)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_list
bw_log "3" "finished ACTION: ${bw_action}"
;;
mount)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_mount ${bw_o_mountbck} ${bw_o_mountdir}
bw_log "3" "finished ACTION: ${bw_action}"
;;
prune)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_prune
bw_log "3" "finished ACTION: ${bw_action}"
;;
shell)
bw_log "3" "running ACTION: ${bw_action}"
f-bw_shell
bw_log "3" "finished ACTION: ${bw_action}"
;;
*)
f-bw_help
exit 0
;;
esac
bw_log "3" "Exiting BORG-WRAPPER - thanks for using me ;)"
exit 0