-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.sh
executable file
·57 lines (46 loc) · 1.33 KB
/
snapshot.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
#! /bin/bash
# Creates a new snapshot when backups have completed.
# The first argument passed should be the base directory for the source
# and repository.
#
# The second argument should be a date string to be used
# for naming the backup directory (snapshot).
#
# Remaining arguments are the rules passed to the culling script.
#
# After the snapshot is created, old backups will then be culled
# according to the rules passed.
#
# This file cannot be run standalone, as it relies on the configuration
# settings externally defined.
if [[ $# < 2 ]]; then
printf "ERROR: required argument missing." >&2
exit 1
fi
backup_root="$1"
shift
timestamp="$1"
shift
ruleset="$*"
backup_source="${backup_root}/${BACKUP_DIR}"
backup_repo="${backup_root}/${BACKUP_REPOSITORY}"
# Dates are in ISO-8601 format, but we want to remove the colons to be safe
# in filenames.
dan=$(echo "$timestamp" | tr : $COLON_REPLACEMENT)
sn_name="${backup_repo}/${dan}"
# Make the snapshot
case "$SNAPSHOT_METHOD" in
btrfs | BTRFS )
btrfs subvol snapshot -r $backup_source $sn_name
;;
cp | copy | COPY )
cp -r $backup_source $sn_name
;;
*)
echo "Unrecognized Snapshot Method - no snapshot created." >&2
exit 1
;;
esac
# Now cull the old ones
echo "Snapshot ${sn_name} complete. Culling old backups..." >>$LOG_FILE
$SCRIPT_DIR/cull.sh "$backup_repo" "$ruleset"