-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvolume-backup.sh
executable file
·74 lines (58 loc) · 1.54 KB
/
volume-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
#!/bin/bash
set -eu
BASEDIR=$(dirname $(realpath $0))
source ${BASEDIR}/volume-backup-common.sh
OUT_DIR="${1:-}"
if [ -z "${OUT_DIR}" ]; then
echo "Usage: $0 OUTPUT_DIRECTORY"
exit 1
fi
if [ ! -d "${OUT_DIR}" ]; then
echo "${OUT_DIR}: No such directory"
exit 1
fi
OUT_DIR=$(realpath ${OUT_DIR})
call_on_error()
{
make occ-maintenancemode-off
}
NAME=nextcloud-gfarm-backup-$(date +%Y%m%d-%H%M)
NAME_TAR=${NAME}.tar
NAME_ENC=${NAME_TAR}.enc
WORKDIR=${TMPDIR}/${NAME}
cd ${BASEDIR}
mkdir ${WORKDIR}
make occ-maintenancemode-on
# "tar: file changed as we read it" may occur
# immediately after starting maintenancemode-on
retry() {
RETRY=5
for i in $(seq ${RETRY}); do
"$@" && return 0
done
}
for vol in $(make -s volume-list); do
echo "copying volume: ${vol}"
retry ${DOCKER} run --rm \
-v "${vol}:/${vol}:ro" \
-v "${WORKDIR}:/backup" \
--workdir / \
--entrypoint tar \
${IMAGE} \
cpf "/backup/volume-${vol}.tar.bz2" \
--use-compress-prog=${COMPRESS_PROG} "${vol}"
done
for name in "${BACKUP_FILES[@]}"; do
cp -a "./${name}" "${WORKDIR}/${name}"
done
make -s version > "${WORKDIR}/${VERSION_FILE_NAME}"
${DOCKER} run --rm \
-v "${WORKDIR}:/${NAME}:ro" \
-v "${OUT_DIR}:/output" \
--workdir / \
--entrypoint tar \
${IMAGE} \
cpf "/output/${NAME_TAR}" -C / ${NAME}
make occ-maintenancemode-off
P=$(realpath ${OUT_DIR}/${NAME_TAR})
echo "Backup file is created: ${P}"