forked from leaf-node/kaya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kaya-client
executable file
·71 lines (58 loc) · 2 KB
/
kaya-client
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
#!/bin/bash
# This file is part of Kaya.
#
# Kaya is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Kaya is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Kaya. If not, see <https://www.gnu.org/licenses/>.
#
# Copyright 2021 Andrew Engelbrecht
#
if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
set -eE -o pipefail
trap 'echo kaya-client: command exit code $?: $BASH_COMMAND >&2' ERR
preferred_protocol_version=2
read -r kaya_protocol_version
case $kaya_protocol_version in
1|2)
;;
*)
echo "kaya-client: error: mismatched protocol version with kaya" >&2
echo "kaya-client: error: kaya protocol version: ${kaya_protocol_version} kaya-client protocol version: ${preferred_protocol_version}" >&2
exit 1
;;
esac
read -r password
port="$1"
hostname="$2"
shift 2
username="${hostname}"
backupdir="${hostname}"
export RESTIC_REPOSITORY="rest:http://${username}:${password}@localhost:${port}/${backupdir}/"
export RESTIC_PASSWORD="${password}"
cmd=( restic backup "$@")
ret=0
"${cmd[@]}" || ret=$?
case $ret in
0)
# success
;;
3)
# restic warning, such as file randomly disappearing during backup
# consider it success
;;
*)
echo "kaya-client: command exit code $ret: ${cmd[*]}" >&2
exit $ret
esac
# needed in case ssh dies on the backup server, and exits with 0 (patched in OpenSSH version 8.8)
if [[ $kaya_protocol_version -ge 2 ]] ; then echo "KAYA_SUCCESSFUL_BACKUP_MESSAGE" ; fi