-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_job
executable file
·82 lines (66 loc) · 2.01 KB
/
run_job
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
#!/bin/bash
#
# Backup remote servers via rsync to a zfs dataset and snapshot it when done.
#
#
# Common settings
#
# set this to container root or leave empty if running outside container
CTROOT=/var/lib/lxc/backups/rootfs
if [ $# -lt 1 ]; then
echo "ERROR: insufficient paramaters. This command requires a job conf file"
echo "as the first parameter on the command line.\n"
echo "optional second parameter: -q (quiet)"
echo "mandatory third: path to logfile."
exit 1
elif [ $# -eq 2 ]; then
echo "ERROR: When using second parameter (-q), path to logfile is also required"
exit 2
elif [ $# -ge 3 ]; then
if [ -e "$3" ]; then
echo "ERROR: logfile exists. We don't want to overwrite anything!"
exit 3
fi
if [ ! -d "`dirname $3`" ]; then
echo "ERROR: logfile directory doesn't exist!"
exit 4
fi
# redirect output to logfile
exec 2>&1 >"$3"
fi
if [ ! -r $1 ]; then
echo "ERROR: config file $1 is not readable."
exit 5
fi
TIMESTAMP=`date +%Y-%m-%d-%H%M`
# source the configuration file
source $1
DATASETMOUNT=`zfs get -H -o value mountpoint $DSTSET`
if [ $? -ne 0 -o -z "${DATASETMOUNT}" ]; then
echo "ERROR: dataset $DSTSET doesn't exist or is not mounted."
exit 6
fi
# unset CTROOT if it's /... no need to cut off the first slash from
# destination directory if we're not in a container.
if [[ $CTROOT == '/' ]]; then
unset CTROOT
fi
if [[ $DATASETMOUNT != ${CTROOT}* ]]; then
echo "dataset is not in this container, check configuration"
exit 7
fi
DST=${DATASETMOUNT/${CTROOT}}
if [ ! -r ${DST}/BACKUPTEST ]; then
echo "${DST}/BACKUPTEST not readable, please check..."
exit 8
elif ! grep -q ${DSTSET} ${DST}/BACKUPTEST; then
echo "${DST}/BACKUPTEST does not contain ${DSTSET}... something is wrong, please check."
exit 8
fi
for SRCMNT in $SRCMNTS; do
echo "START ${SRC}${SRCMNT}/ -> ${DST}/${SRCMNT}/..."
$RSYNCCMD ${SRC}/${SRCMODULE}${SRCMNT}/ ${DST}/${SRCMNT}/
echo -e "\n\n\n"
done
echo "doing zfs-auto-snapshot $DSTSET..."
zfs-auto-snapshot -l backup -k 14 ${DSTSET}