aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar TheMightyV <themightyv@protonmail.com> 2022-01-04 22:41:10 +0100
committerGravatar TheMightyV <themightyv@protonmail.com> 2022-01-04 22:41:10 +0100
commitcba2d63889fa3ae640d213ab2c15f99d3d941967 (patch)
treed1fe7b5b2dcd183ada011e86c850c0329ad5ccf0
parentc94132808d2a3499f19f86424bfdedf9e0c39312 (diff)
downloadminecraft-server-tools-cba2d63889fa3ae640d213ab2c15f99d3d941967.tar.gz
optional password protection of borg repo
fixed borg backup check added nanoseconds to old world backup to prevent collision during tests
-rw-r--r--backends/borg.sh12
-rwxr-xr-xserver.sh9
2 files changed, 17 insertions, 4 deletions
diff --git a/backends/borg.sh b/backends/borg.sh
index 5d7b2c7..b8854a1 100644
--- a/backends/borg.sh
+++ b/backends/borg.sh
@@ -1,9 +1,17 @@
function borg_init() {
+ local encryption
+ if [ -z "$BACKUP_PASSCOMMAND" ] ; then
+ echo "borg: no password given, repository is not protected"
+ encryption="none"
+ else
+ encryption="repokey-blake2"
+ fi
+
export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
for backup_dir in ${BACKUP_DIRS[*]}
do
# borg will check if repo exists
- borg init --encryption=repokey-blake2 "$backup_dir"
+ borg init --encryption="$encryption" "$backup_dir"
done
}
@@ -78,5 +86,7 @@ function borg_restore() {
local dest="$3"
export BORG_REPO="$remote"
+ cd "$dest"
borg extract "${remote}::${snapshot}"
+ cd - > /dev/null
}
diff --git a/server.sh b/server.sh
index 1f4f8e1..d68a203 100755
--- a/server.sh
+++ b/server.sh
@@ -140,6 +140,9 @@ function init_backup() {
function same_world() {
delta=$(diff -r "$1" "$2")
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
if [ -z "$delta" ] ; then
return 0
fi
@@ -366,8 +369,8 @@ function server_restore() {
local oldworld_name
if [ "$dest" = "$PWD" ] && [[ -d "$WORLD_NAME" ]]; then
echo -n "Preserving old world: "
- oldworld_name="${WORLD_NAME}.old.$(date +'%F_%H-%M-%S')"
- mv -v "$PWD/$WORLD_NAME" "$PWD/$oldworld_name"
+ oldworld_name="${WORLD_NAME}.old.$(date +'%F_%H-%M-%S.%N')"
+ mv -n -v "$PWD/$WORLD_NAME" "$PWD/$oldworld_name"
fi
@@ -389,7 +392,7 @@ function server_restore() {
return 1
fi
- echo "Snapshot restored"
+ echo_debug "Snapshot restored"
return 0
}