summaryrefslogtreecommitdiffstats
path: root/bin/bakdbdr
blob: 4ece6faae374b2ba8cca047b7a39161c4a68a468 (plain)
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
#!/bin/sh

set -eu

backup()
{
	local db_file="${1}"
	shift 1
	local bk_file=

	bk_file="${db_file}.$(TZ=UTC date '+%Y%m%dT%H%M%SZ')"

	bakdb "${db_file}" "${bk_file}"

	printf '%s.xz' "${bk_file}"
	return 0
}

remote_copy()
{
	local bk_file="${1}"
	local remote="${2}"
	shift 1

	rsync -a "${bk_file}" "${remote}"

	return 0
}

usage()
{
	printf 'Usage: %s <database-file> [<user>@]<host>:<dest>\n' "${0}"

	return 0
}

main()
{
	local db_file=
	local remote=

	if [ ${#} -ne 2 ]; then
		usage 1>&2
		return 1
	fi
	db_file="${1}"
	remote="${2}"
	shift 2

	case "${remote}" in
		?*':'*) ;;
		*)
			usage 1>&2
			return 1
			;;
	esac

	remote_copy "$(backup "${db_file}")" "${remote}"

	return 0
}

main "${@}"