-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtarsnap-archive.sh
executable file
·53 lines (42 loc) · 1.19 KB
/
tarsnap-archive.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
#!/usr/bin/env bash
# Tarsnap backup script
# Written by Tim Bishop, 2009.
# Modified by Pronoiac, 2014.
# Directories to backup - set in
CONFIG=/etc/tarsnap-cron.conf
# CONFIG=tarsnap-cron.conf
# note: this evals the config file, which can present a security issue
# unless it's locked with the right permissions - e.g. not world-writable
if [ ! -r "$CONFIG" ] ; then
echo "ERROR: Couldn't read config file $CONFIG"
echo Exiting now!
exit 1
fi
source $CONFIG
timestamp=`date +%Y-%m-%d-%H%M`
if [ -z $1 ]
then
echo 1>&2 First parameter should be hourly, daily, weekly, monthly, as appropriate.
exit 1
fi
# the last part of the suffix is now specified on the command line
# cron should call this with daily, weekly, monthly, as appropriate
# typical suffix: 2014-02-22-1920-daily
if [ $# -ne 0 ]
then
SUFFIX=$timestamp-$1
else
SUFFIX=$timestamp
fi
# end of config
# Do backups
echo Starting backups.
for BACKUP in "${BACKUP_ARRAY[@]}"; do
SPLIT=(${BACKUP//=/ })
# typical label & path: www and /var/www
label=${SPLIT[0]}
path=${SPLIT[1]}
echo "==> create $PREFIX-$label-$SUFFIX"
cd $path && \
$TARSNAP $EXTRA_PARAMETERS -c -f $PREFIX-$label-$SUFFIX .
done