-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_encrypted_borgbackup.sh
executable file
·83 lines (68 loc) · 2.39 KB
/
export_encrypted_borgbackup.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
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
#!/bin/bash
#
# Exports an encrypted borg backup to a tar.gpg file
#
# The MIT License (MIT)
#
# Copyright (c) 2019-present Georg Lutz <georg@georglutz.de>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
set -eu
script_name=$(basename "$0")
function help()
{
echo "Exports an encrypted borg backup to a tar.gpg file"
echo ""
echo ""
echo "Usage:"
echo "$script_name archive outfile"
echo ""
echo " archive: The borg archive to export."
echo " outfile: Full path of the resulting tar.gpg file."
echo ""
echo "The necessary information is expected to be available in environment variables"
echo "like BORG_REPO and BORG_PASSPHRASE / BORG_PASSCOMMAND."
echo "Hint: They won't show up in Bash history when you prefix the export command with a space."
echo "The archives can be listed e.g. by 'borg list' and referenced like ::<archive-name>."
}
function error()
{
local lineno="$1"
echo "Error in line $lineno"
exit 1
}
trap 'error ${LINENO}' ERR
if [ $# -ne 2 ]; then
help
exit 1
fi
opt_archive="$1"
opt_outfile="$2"
set +e
echo "Checking archive $opt_archive ..."
borg info $opt_archive
rc=$?
if [ $rc -ne 0 ]; then
echo "borg info did not return 0. Exit"
exit 1
fi
echo "Running borg export-tar ..."
borg export-tar --progress $opt_archive - | gpg --encrypt --sign --default-recipient-self -o "$opt_outfile"
echo "Finished successfully"