summaryrefslogtreecommitdiff
path: root/sysutils/boxbackup-devel/files/999.boxbackup.in
blob: 62e583372d9f1603e8cc4dcb85f730d7e7ffcd76 (plain) (blame)
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
82
#!/bin/sh
#
# Box Backup monthly store compare
#
# Add the following to /etc/periodic.conf to enable the monthly compare:
#  monthly_boxbackup_compare_enable="YES"
#
# By default the script will run "compare -aq". If you want to change this to
# run a full compare, add the following to periodic.conf:
#  monthly_boxbackup_compare_args="-a"
#
# NOTE: This script will cause the monthly periodic(8) run to take much longer
# than usual, depending on the size of your backup store.
#
# If you wish to run this independently of the monthly job, you can create a
# new periodic entry as follows:
#
#  # mkdir /usr/local/etc/periodic/boxbackup
#  # mv /usr/local/etc/periodic/monthly/999.boxbackup \
#       /usr/local/etc/periodic/boxbackup/100.compare
#
# Then add the following to /etc/crontab:
# 30      5       1       *       *       root    periodic boxbackup
#
# (adjust the timings as necessary)
#
# You may also wish to add boxbackup_output="root" to periodic.conf so that
# mail comes from periodic rather than cron.

monthly_boxbackup_compare_enable="NO"
monthly_boxbackup_compare_args="-aq"

if [ -r /etc/defaults/periodic.conf ]
then
	. /etc/defaults/periodic.conf
	source_periodic_confs
fi

SLEEP=/bin/sleep
JOT=/usr/bin/jot

random() {
	${JOT} -r 1 0 900
}

rc=0

case "$monthly_boxbackup_compare_enable" in
	[Yy][Ee][Ss])
		echo
		echo "Running Box Backup store compare:"
		# When non-interactive, sleep to reduce congestion on rkhunter
		# site
		if [ "$1" != -nodelay ]; then
			# In FreeBSD 12.0 the anticongestion function should
			# be used instead of a hard-coded sleep
			if [ -n "$anticongestion_sleeptime" ]; then
				anticongestion
			else
				${SLEEP} $(random)
			fi
		fi
		%%PREFIX%%/sbin/bbackupquery -q "compare -c $monthly_boxbackup_compare_args" quit

		# Return codes:
		#  1    Comparison was exact
		#  2    Differences were found
		#  3    An error occurred
		if [ $? -eq 2 ]; then
			echo
			echo "Differences were found. Please check the output."
			rc=3
		elif [ $? -eq 3 ]; then
			echo
			echo "An error occurred. Please check the output."
			rc=3
		fi

		;;
esac

exit $rc