Skip to content

Commit d8e7e52

Browse files
committed
2025-07-03 05:19:31
1 parent a78d9da commit d8e7e52

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

app.backup_fs.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ FS_TPL="${FS_TPL:?}"; readonly FS_TPL
2929
ENC_ON="${ENC_ON:?}"; readonly ENC_ON
3030
ENC_APP="${ENC_APP:?}"; readonly ENC_APP
3131
ENC_PASS="${ENC_PASS:?}"; readonly ENC_PASS
32+
SSH_ON="${SSH_ON:?}"; readonly SSH_ON
33+
SSH_HOST="${SSH_HOST:?}"; readonly SSH_HOST
34+
SSH_USER="${SSH_USER:?}"; readonly SSH_USER
35+
SSH_PASS="${SSH_PASS:?}"; readonly SSH_PASS
36+
SSH_DST="${SSH_DST:?}"; readonly SSH_DST
37+
SSH_MNT="${SSH_MNT:?}"; readonly SSH_MNT
3238
RSYNC_ON="${RSYNC_ON:?}"; readonly RSYNC_ON
3339
RSYNC_HOST="${RSYNC_HOST:?}"; readonly RSYNC_HOST
3440
RSYNC_USER="${RSYNC_USER:?}"; readonly RSYNC_USER
@@ -131,10 +137,9 @@ function _enc() {
131137
}
132138

133139
function _sum() {
134-
local in; in="${1}"; (( "${ENC_ON}" )) && in="${1}.${ENC_APP}"
135-
local out; out="${in}.txt"
140+
local f; f="${1}"; (( "${ENC_ON}" )) && f="${1}.${ENC_APP}"
136141

137-
sha256sum "${in}" | sed 's| .*/| |g' | tee "${out}" > '/dev/null'
142+
sha256sum "${f}" | sed 's| .*/| |g' | tee "${f}.txt" > '/dev/null'
138143
}
139144

140145
function _ssh() {
@@ -175,23 +180,23 @@ function fs_check() {
175180

176181
function fs_backup() {
177182
local ts; ts="$( date -u '+%m.%d-%H' )"
178-
local tpl; tpl="${FS_DST}/${FS_TPL}"
183+
local dst; dst="${FS_DST}/${FS_TPL}"
179184
local file; file="$( hostname -f ).${ts}.tar.xz"
180185
local msg; msg=()
181186

182187
for i in "${!FS_SRC[@]}"; do [[ -e "${FS_SRC[i]}" ]] || unset 'FS_SRC[i]'; done
183-
[[ ! -d "${tpl}" ]] && mkdir -p "${tpl}"; cd "${tpl}" || _msg 'error' "Directory '${tpl}' not found!"
184-
if tar -cf - "${FS_SRC[@]}" | xz | _enc "${tpl}/${file}" && _sum "${tpl}/${file}"; then
188+
[[ ! -d "${dst}" ]] && mkdir -p "${dst}"; cd "${dst}" || _msg 'error' "Directory '${dst}' not found!"
189+
if tar -cf - "${FS_SRC[@]}" | xz | _enc "${dst}/${file}" && _sum "${dst}/${file}"; then
185190
msg=(
186191
'success'
187192
"Backup of files ('${file}') completed successfully"
188-
"Backup of files ('${file}') completed successfully. File '${tpl}/${file}' received."
193+
"Backup of files ('${file}') completed successfully. File '${dst}/${file}' received."
189194
); _mail "${msg[@]}"; _gitlab "${msg[@]}"; _msg 'success' "${msg[2]}"
190195
else
191196
msg=(
192197
'error'
193198
"Error backing up files ('${file}')"
194-
"Error backing up files ('${file}')! File '${tpl}/${file}' not received or corrupted!"
199+
"Error backing up files ('${file}')! File '${dst}/${file}' not received or corrupted!"
195200
); _mail "${msg[@]}"; _gitlab "${msg[@]}"; _msg 'error' "${msg[2]}"
196201
fi
197202
}

0 commit comments

Comments
 (0)