Skip to content

Commit f401a06

Browse files
committed
updated server.sh
1 parent b34b0f6 commit f401a06

2 files changed

Lines changed: 87 additions & 3 deletions

File tree

src/borg/core.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ if ! source "$borg_conf_file"; then
1111
exit 1
1212
fi
1313

14-
# loading server script
15-
source "$BORG_WORKING_DIR/server.sh"
14+
source "$BORG_WORKING_DIR/server.sh" # borg server

src/borg/server.sh

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,89 @@
11
#!/bin/bash
22

33
# === vars ===
4-
[[ -v BORG_RSH && -f "$SSH_KEYFILE" ]] && export BORG_RSH
4+
5+
# borg repo
6+
if [[ -v BORG_REPO && -v BORG_PASSPHRASE ]]; then
7+
export BORG_REPO
8+
export BORG_PASSPHRASE
9+
else
10+
echo "both vars *BORG_REPO* & *BORG_PASSPHRASE* have to be set"
11+
exit 1
12+
fi
13+
14+
# ssh auth
15+
if [[ -v BORG_RSH ]]; then
16+
if [[ -f "$SSH_KEYFILE" ]]; then
17+
export BORG_RSH
18+
else
19+
echo "*$SSH_KEYFILE* not found"
20+
exit 1
21+
fi
22+
fi
23+
24+
# mounting location; creates folder if not existing
25+
if [[ -v MOUNT_DIR && -n "$MOUNT_DIR" ]]; then
26+
prefix="mounting location *$MOUNT_DIR* ... "
27+
if [[ -d "$MOUNT_DIR" ]]; then
28+
echo "$prefix" "exists"
29+
else
30+
if mkdir -p "$MOUNT_DIR"; then
31+
echo "$prefix" "created"
32+
else
33+
echo "$prefix" "can't be created"
34+
exit 1
35+
fi
36+
fi
37+
else
38+
echo "var *MOUNT_DIR* have to be set"
39+
exit 1
40+
fi
41+
42+
# === pre func ===
43+
# checks if connection works
44+
validate_borg_conn() {
45+
borg info 1> /dev/null && return 0
46+
return 1
47+
}
48+
49+
# checks if archives are there to recover from
50+
validate_borg_archive() {
51+
borg list | grep -q . && return 0
52+
return 1
53+
}
54+
55+
# === post func ===
56+
# get archive (for now latest one)
57+
latest_borg_archive() {
58+
latest=$(borg list --short | tail -n 1)
59+
[[ -n "$latest" ]] && return 0
60+
return 1
61+
}
62+
63+
# === main ===
64+
prefix="repo: *$BORG_REPO* ... "
65+
# checks if connection is working
66+
if validate_borg_conn; then
67+
echo "$prefix" "connection successful"
68+
else
69+
echo "$prefix" "connection unsuccessful"
70+
exit 1
71+
fi
72+
73+
# checks if at least one archive is there
74+
if ! validate_borg_archive; then
75+
echo "no archives can be found"
76+
exit 1
77+
fi
78+
79+
# gets latest archive
80+
prefix="archive: "
81+
latest=$(borg list --short | tail -n 1)
82+
if [[ -n "$latest" ]]; then
83+
echo "$prefix" "$latest"
84+
else
85+
echo "$prefix" "not found"
86+
exit 1
87+
fi
88+
89+
# makes

0 commit comments

Comments
 (0)