Skip to content

Commit d53d978

Browse files
committed
Update resources
1 parent e12e403 commit d53d978

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

app.backup_fs.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,18 @@ LOG_CHECK="${SRC_DIR}/log.check"
5454
LOG_BACKUP="${SRC_DIR}/log.backup"
5555
LOG_SYNC="${SRC_DIR}/log.sync"
5656
LOG_CLEAN="${SRC_DIR}/log.clean"
57+
LOG_TS="$( date '+%FT%T%:z' ) $( hostname -f ) ${SRC_NAME}"
5758

5859
# -------------------------------------------------------------------------------------------------------------------- #
5960
# -----------------------------------------------------< SCRIPT >----------------------------------------------------- #
6061
# -------------------------------------------------------------------------------------------------------------------- #
6162

62-
function _msg() {
63-
local type; type="${1}"
64-
local msg; msg="$( date '+%FT%T%:z' ) $( hostname -f ) ${SRC_NAME}: ${2}"
63+
function _error() {
64+
echo "${LOG_TS}: $*" >&2; exit 1
65+
}
6566

66-
case "${type}" in
67-
'error') echo "${msg}" >&2; exit 1 ;;
68-
'success') echo "${msg}" ;;
69-
*) exit 1 ;;
70-
esac
67+
function _success() {
68+
echo "${LOG_TS}: $*" >&2
7169
}
7270

7371
function _mail() {
@@ -112,6 +110,17 @@ function _gitlab() {
112110
EOF
113111
}
114112

113+
function _msg() {
114+
_mail "${1}" "${2}" "${3}"
115+
_gitlab "${1}" "${2}" "${3}"
116+
117+
case "${1}" in
118+
'error') _error "${3}" ;;
119+
'success') _success "${3}" ;;
120+
*) _error "'MSG_TYPE' does not exist!" ;;
121+
esac
122+
}
123+
115124
function _gpg() {
116125
gpg --batch --passphrase "${2}" --symmetric --output "${1}.gpg" \
117126
--s2k-cipher-algo "${ENC_S2K_CIPHER:-AES256}" \
@@ -129,7 +138,7 @@ function _enc() {
129138
case "${ENC_APP}" in
130139
'gpg') _gpg "${1}" "${ENC_PASS}" ;;
131140
'ssl') _ssl "${1}" "${ENC_PASS}" ;;
132-
*) _msg 'error' 'ENC_APP does not exist!' ;;
141+
*) _error 'ENC_APP does not exist!' ;;
133142
esac
134143
else
135144
cat < '/dev/stdin' > "${1}"
@@ -166,7 +175,7 @@ function fs_mount() {
166175
"Error mounting SSH FS to '${SSH_MNT}'!"
167176
)
168177

169-
_ssh "${SSH_DST}" "${SSH_MNT}" || { _mail "${msg[@]}"; _gitlab "${msg[@]}"; _msg "${msg[0]}" "${msg[2]}"; }
178+
_ssh "${SSH_DST}" "${SSH_MNT}" || _msg "${msg[@]}"
170179
}
171180

172181
function fs_check() {
@@ -175,7 +184,7 @@ function fs_check() {
175184
'error'
176185
"File '${file}' not found!"
177186
"File '${file}' not found! Please check the remote storage status!"
178-
); _mail "${msg[@]}"; _gitlab "${msg[@]}"; _msg "${msg[0]}" "${msg[2]}"
187+
); _msg "${msg[@]}"
179188
}
180189

181190
function fs_backup() {
@@ -190,8 +199,7 @@ function fs_backup() {
190199

191200
for i in "${!FS_SRC[@]}"; do [[ -e "${FS_SRC[i]}" ]] || unset 'FS_SRC[i]'; done
192201
[[ ! -d "${dst}" ]] && mkdir -p "${dst}"; cd "${dst}" || _msg "${msg[0]}" "Directory '${dst}' not found!"
193-
{ { tar -cf - "${FS_SRC[@]}" | xz | _enc "${dst}/${file}"; } && _sum "${dst}/${file}"; } \
194-
|| { _mail "${msg[@]}"; _gitlab "${msg[@]}"; _msg "${msg[0]}" "${msg[2]}"; }
202+
{ { tar -cf - "${FS_SRC[@]}" | xz | _enc "${dst}/${file}"; } && _sum "${dst}/${file}"; } || _msg "${msg[@]}"
195203
}
196204

197205
function fs_sync() {
@@ -203,7 +211,7 @@ function fs_sync() {
203211
'Error synchronizing with remote storage!'
204212
)
205213

206-
_rsync "${FS_DST}" "${RSYNC_DST}" || { _mail "${msg[@]}"; _gitlab "${msg[@]}"; _msg "${msg[0]}" "${msg[2]}"; }
214+
_rsync "${FS_DST}" "${RSYNC_DST}" || _msg "${msg[@]}"
207215
}
208216

209217
function fs_clean() {

0 commit comments

Comments
 (0)