-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackupnow
executable file
·70 lines (59 loc) · 1.28 KB
/
backupnow
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
#! /usr/bin/env bash
set -euo pipefail
## Default variable
export VERBOSE_FLAG=""
command=local_backup
## Parse options
# Require gnu-getopt
OPTIONS=$(getopt -n "$0" -o hrv --long "help,remote,verbose" -- "$@")
eval set -- "$OPTIONS"
while true; do
case "$1" in
-v | --verbose)
export VERBOSE_FLAG="--verbosity 2"
shift
;;
-r | --remote)
command=remote_backup
shift
;;
-h | --help)
help
exit 0
;;
--)
shift
break
;;
*)
help
exit 1
;;
esac
done
function help() {
echo "usage: $(basename $0) [--remote|--help] [--verbose]"
}
function get_password() {
# Get borg backup passphrase
export BORG_PASSPHRASE="$(pass show ${1})"
}
function remote_backup() {
get_password backup/rsync.net.borg-repository
# Backup the shit
borgmatic -c ~/.config/borgmatic/rsync.net.yaml create ${VERBOSE_FLAG}
# Prune after the backup, I find that way better
borgmatic -c ~/.config/borgmatic/rsync.net.yaml prune ${VERBOSE_FLAG}
}
function local_backup() {
get_password backup/hdd.borg-repository
# This is done to allow only one sudo for both steps
sudo -E bash -c "
# Backup the shit
borgmatic -c .config/borgmatic/hdd.yaml --create $VERBOSE_FLAG
# Prune the stuff
borgmatic -c .config/borgmatic/hdd.yaml --prune $VERBOSE_FLAG
"
}
# Run the script
$command