aboutsummaryrefslogtreecommitdiffstats
path: root/lifeboat
blob: 244f7328ee1bfa6e1d98cd15229c70f39a043cb7 (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
#!/bin/sh

set -e

errx() {
	printf "lifeboat: %s\n" "$1" >&2
	exit 1
}

usage() {
	printf "usage: lifeboat repo [run|restic-cmd]\n"
	exit 0
}

run_backup() {
	(
		cd "$rootdir/$repo"
		./run
		for i in post sync; do
			test -x $i && ./$i
		done
	)
}

rootdir=${LIFEBOAT_ROOT:-"/srv/backup/lifeboat"}

test $# -lt 2 && usage

repo=$1
shift

test -d "$repo" || errx "$repo: no such repository"

export LIFEBOAT_REPO_NAME=$repo
export RESTIC_REPOSITORY=$rootdir/$repo/repo
export RESTIC_PASSWORD_FILE=$rootdir/$repo/credentials/restic

case "$1" in
	run) run_backup;;
	*) restic "$@";;
esac