aboutsummaryrefslogtreecommitdiff
path: root/src/bin/backup
blob: 828b96a8e529840fbd248c85d22162332bbc02d6 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
set -u

usage() {
	cat <<-'EOF'
		Usage:
		  backup [ARCHIVE_TAG [COMMENT]]
		  backup -h
	EOF
}

help() {
	cat <<-'EOF'

		ARCHIVE_TAG defaults to "cronjob".
		COMMENT defaults to an empty string.

		Options:
		  -h, --help    show this message
	EOF
}

for flag in "$@"; do
	case "$flag" in
		--)
			break
			;;
		--help)
			usage
			help
			exit
			;;
		*)
			;;
	esac
done

VERBOSE_FLAG=''
while getopts 'hv' flag; do
	case "$flag" in
		h)
			usage
			help
			exit
			;;
		v)
			VERBOSE_FLAG='-v'
			;;
		*)
			usage >&2
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))


set -x

finish() {
	STATUS=$?
	printf '\n>>>\n>>> exit status: %s\n>>>\n\n' "$STATUS" >&2
}
trap finish EXIT


export BORG_REMOTE_PATH='borg1'
export BORG_PASSCOMMAND='pass show Usurpador/borg/passphrase'
SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
export SSH_AUTH_SOCK

borg init -e repokey-blake2 suyin:borg/usurpador ||:
borg key export suyin:borg/usurpador ~/archive/usurpador-borg-key.txt

borg create \
	$VERBOSE_FLAG                                          \
	--exclude ~/.cache                                     \
	--stats                                                \
	--compression lzma,9                                   \
	--comment "${2:-}"                                     \
	"suyin:borg/usurpador::{hostname}-{now}-${1:-cronjob}" \
	~/

borg check \
	--verbose \
	--last 3  \
	suyin:borg/usurpador

borg prune \
	--verbose         \
	--list            \
	--keep-within=6m  \
	--keep-weekly=52  \
	--keep-monthly=24 \
	suyin:borg/usurpador

ssh suyin quota