-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.sh
32 lines (30 loc) · 1.05 KB
/
lib.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
# Ask for a restic password and store it in an env. var. if not already stored
resticAskPass() {
if [ -z "$RESTIC_PASSWORD" ]; then echo "Enter the backup password: " && read -s RESTIC_PASSWORD; fi
}
# Check to see if all env. vars. needed for a Restic command to run (excluding the password) exist
resticEnsureVars() {
if [ -z "$REMOTEPATH" ] || [ -z "$LOCALPATH" ]; then
echo "One or more required variables are missing" >&2
exit 1
fi
if [ -n "$TARGETBUCKET" ]; then
if [ -z "$B2_ACCOUNT_ID" ] || [ -z "$B2_ACCOUNT_KEY" ]; then
echo "One or more required variables are missing" >&2
exit 1
fi
fi
}
# Run Restic with the provided options if all required env. vars. exist
resticLocalCommand() {
resticEnsureVars
resticAskPass
export B2_ACCOUNT_ID=$B2_ACCOUNT_ID
export B2_ACCOUNT_KEY=$B2_ACCOUNT_KEY
export RESTIC_PASSWORD=$RESTIC_PASSWORD
repo="$REMOTEPATH"
if [ -n "$TARGETBUCKET" ]; then
repo="b2:$TARGETBUCKET:$REMOTEPATH"
fi
restic --repo "$repo" ${1}
}