forked from datajoint-company/dbbak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbbak.cron
executable file
·56 lines (47 loc) · 842 Bytes
/
dbbak.cron
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
#! /bin/sh
#
# dbbak.cron: cron driver for dbbak.
#
PATH="/sbin:/bin:"
PATH="${PATH}:/usr/sbin:/usr/bin:"
PATH="${PATH}:/usr/local/sbin:/usr/local/bin:"
export PATH;
usage_exit() {
echo "usage: $me [daily|weekly]"
exit 1;
}
err_exit() {
echo "$me: error: $*"
exit 1;
}
lock() {
[ -f "$lockfile" ] \
&& err_exit "lock(): lockfile $lockfile exists" \
|| hostname > $lockfile
}
unlock(){
[ -f "$lockfile" ] \
&& rm -f $lockfile \
|| err_exit "unlock(): lockfile $lockfile does not exist!"
}
#
# _start:
#
me="`basename $0`"
me=${me%.cron}
. /etc/${me}.cfg
[ -z "$DBBAK_BKDIR" ] && err_exit "misconfigured."
lockfile="${DBBAK_BKDIR}/dbbak.cron.lock";
lock;
[ "$#" -lt "1" ] && usage_exit;
case $1 in
"daily")
dbbak incremental;;
"weekly")
dbbak purge;
dbbak rotate;
dbbak full;;
*)
usage_exit;;
esac
unlock;