blob: b64175c2d9c582b93444877d640af22ee61bf247 (
plain)
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
|
#!/usr/bin/env bash
#
# This script is mostly included "as is", I did this quite a while ago and (also see todo remarks)
# I'm not happy yet, but it works fine and the core mechanisms are swell.
#
# shellcheck disable=SC1091
source /etc/lirion/nextcloud.conf || exit 1
# shellcheck disable=SC1091
source /usr/lib/lirion/ln-initfunctions || exit 2
# TODO: Parametrise file directory and pw acquisition - better design and more secure
BDBDIR="${NCDBBKPDIR}/files"
PWFL="${NCDBBKPDIR}/pw"
TIME="$(date +"%Y-%m-%dT%H:%M:%S%z")"
#########
# MYSQL #
#########
DUMPOPTS=( "--add-drop-table" "--add-locks" )
DUMPOPTS+=( "--complete-insert" "--create-options" "--lock-tables" )
printf "File timestamp: %s\n" "$TIME"
DBARR=( "$NCDBNAME" )
for i in "${DBARR[@]}";do
lnbegin "DB backup: $i"
sleep 0.1337
lnprog "dump"
if ! mysqldump "${DUMPOPTS[@]}" -u root --password="$(cat "$PWFL")" --databases \
"$i" > "$BDBDIR/$i-$TIME.sql" 2>/dev/null; then
lnfail
exit 120
fi
sleep 0.1337
lnprog "compression"
if ! xz -T4 "$BDBDIR/$i-$TIME.sql" > /dev/null 2>&1 && chmod 0600 \
"$BDBDIR/$i-$TIME.sql.xz" 2>/dev/null; then
lnfail
exit 121
fi
sleep 0.1337
lnok
done
NCVER="$(/usr/bin/sudo -u "$NCUSER" "$NCPHPBIN" "${NCAPPLDIR}/occ" 'status')" || exit 122
NCVER="$(/usr/bin/printf '%b' "$NCVER" | /usr/bin/grep 'version:' | /usr/bin/awk '{print $NF}')" || exit 123
/usr/bin/printf 'Current version: %b\n' "$NCVER"
if [ "$(printf '%b' "$NCVER" | wc -l)" -gt 0 ]; then
printf 'Not a single line: %b\n' "$NCVER" >&2
exit 124
elif [ "$(printf '%b' "$NCVER" | wc -w)" -ne 1 ]; then
printf 'Not a single word: %b\n' "$NCVER" >&2
exit 125
fi
lnbegin "File backup: Nextcloud"
sudo rm -f "${NCAPPLDIR}/../nextcloud-$(date -I)-${NCVER}.tar" \
"${NCAPPLDIR}/../nextcloud-$(date -I)-${NCVER}.tar.xz" || exit 126
sleep 0.1337
lnprog 'dump'
if ! tar -C "${NCAPPLDIR}/.." --checkpoint=32768 --checkpoint-action='.' -cf \
"${NCAPPLDIR}/../nextcloud-$(date -I)-${NCVER}.tar" "$NCAPPLDIR" 2>/dev/null
then
lnfail
exit 127
fi
lnprog 'compression'
if ! xz -T4 "${NCAPPLDIR}/../nextcloud-$(date -I)-${NCVER}.tar" > /dev/null 2>&1 && \
chmod 0600 "${NCAPPLDIR}/../nextcloud-$(date -I)-${NCVER}.tar.xz" 2>/dev/null
then
lnfail
exit 128
fi
lnok
|