aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorGravatar TheMightyV <themightyv@protonmail.com> 2022-01-05 22:04:10 +0100
committerGravatar TheMightyV <themightyv@protonmail.com> 2022-01-05 22:04:10 +0100
commitae5db1b37ae8554dff72b0da42ccbbbbc64baf71 (patch)
tree453b212c75d89f796628b46f1103807a3da9fb8b /backends
parent1ba766d277fc35435ca80b9fcfa28c57468f7bce (diff)
downloadminecraft-server-tools-ae5db1b37ae8554dff72b0da42ccbbbbc64baf71.tar.gz
split echos to debug/info/error levels
unified ls_all backend functions unified backend function calls ls_dir -> ls in backends fixed accidental echo -> log_info replacement
Diffstat (limited to 'backends')
-rw-r--r--backends/borg.sh28
-rw-r--r--backends/bup.sh28
-rw-r--r--backends/tar.sh24
3 files changed, 28 insertions, 52 deletions
diff --git a/backends/borg.sh b/backends/borg.sh
index b0351a0..ec39bc8 100644
--- a/backends/borg.sh
+++ b/backends/borg.sh
@@ -1,7 +1,7 @@
function borg_init() {
local encryption
if [ -z "$BACKUP_PASSCOMMAND" ] ; then
- echo "borg: no password given, repository is not protected"
+ log_info "borg: no password given, repository is not protected"
encryption="none"
else
encryption="repokey-blake2"
@@ -10,9 +10,10 @@ function borg_init() {
export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
for backup_dir in ${BACKUP_DIRS[*]}
do
+ log_debug "Initializing repo at $backup_dir "
# borg will check if repo exists
borg init --encryption="$encryption" "$backup_dir"
- done
+ done
}
function borg_create_backup() {
@@ -22,9 +23,9 @@ function borg_create_backup() {
do
export BORG_REPO="$backup_dir"
- trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
+ trap 'echo [WARNING] $( date ) Backup interrupted >&2; exit 2' INT TERM
- echo "borg: backing up to \"$backup_dir\""
+ log_info "borg: backing up to \"$backup_dir\""
borg create \
"${backup_dir}::${BACKUP_NAME}_$(date +'%F_%H-%M-%S')" \
@@ -35,7 +36,7 @@ function borg_create_backup() {
local backup_exit=$?
- echo_debug "borg: pruning repository at \"$backup_dir\""
+ log_debug "borg: pruning repository at \"$backup_dir\""
borg prune \
--prefix '{hostname}-' \
@@ -53,11 +54,11 @@ function borg_create_backup() {
retcode=$(( global_exit > retcode ? global_exit : retcode ))
if [ ${global_exit} -eq 0 ]; then
- echo_debug "borg: backup and prune finished successfully"
+ log_debug "borg: backup and prune finished successfully"
elif [ ${global_exit} -eq 1 ]; then
- echo "borg: backup and/or prune finished with warnings"
+ log_info "borg: backup and/or prune finished with warnings"
else
- echo "borg: backup and/or prune finished with errors"
+ log_error "borg: backup and/or prune finished with errors"
fi
#exit ${global_exit}
done
@@ -65,20 +66,11 @@ function borg_create_backup() {
}
# server_restore relies on output format of this function
-function borg_ls_dir() {
+function borg_ls() {
export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
borg list "$1" | cut -d' ' -f1 | sort -r
}
-function borg_ls_all() {
- export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
- for backup_dir in ${BACKUP_DIRS[*]}
- do
- echo "borg: backups in \"$backup_dir\":"
- borg list "$backup_dir" | cut -d' ' -f1
- done
-}
-
function borg_restore() {
export BORG_PASSCOMMAND="$BACKUP_PASSCOMMAND"
local remote="$1"
diff --git a/backends/bup.sh b/backends/bup.sh
index d1250de..6aa92b6 100644
--- a/backends/bup.sh
+++ b/backends/bup.sh
@@ -15,14 +15,14 @@ function bup_init() {
bup -d "$(bup_local)" index "$WORLD_NAME"
local status=$?
if [ $status -ne 0 ]; then
- echo_debug "bup: no local repo found, creating..."
+ log_debug "bup: no local repo found, creating..."
bup -d "$(bup_local)" init -r "$(bup_local)"
- echo_debug "bup: created local repo at $(bup_local)"
+ log_debug "bup: created local repo at $(bup_local)"
fi
}
function bup_create_backup() {
- echo_debug "bup: backup started"
+ log_debug "bup: backup started"
bup -d "$(bup_local)" index "$WORLD_NAME"
@@ -31,20 +31,20 @@ function bup_create_backup() {
local retcode=1
for backup_dir in ${BACKUP_DIRS[*]}
do
- echo "bup: backing up to \"$backup_dir\""
+ log_info "bup: backing up to \"$backup_dir\""
# try to save to remote
bup -d "$(bup_local)" save -r "$backup_dir" -n "$BACKUP_NAME" "$WORLD_NAME"
local status=$?
# if failed - reinit remote and try again
if [ $status -ne 0 ]; then
- echo_debug "bup: failed backing up to \"$backup_dir\", reinitializing remote..."
+ log_debug "bup: failed backing up to \"$backup_dir\", reinitializing remote..."
bup -d "$(bup_local)" init -r "$backup_dir"
status=$?
- if [ $status -ne 0 ]; then
- echo_debug "bup: created remote at \"$backup_dir\""
+ if [ $status -eq 0 ]; then
+ log_debug "bup: created remote at \"$backup_dir\""
bup -d "$(bup_local)" save -r "$backup_dir" -n "$BACKUP_NAME" "$WORLD_NAME"
else
- echo "bup: failed to make remote at \"$backup_dir\", moving on"
+ log_error "bup: failed to make remote at \"$backup_dir\", moving on"
fi
else
if [ ! "$backup_dir" = "$(bup_local)" ]; then
@@ -53,24 +53,16 @@ function bup_create_backup() {
fi
done
- echo "bup: backup finished"
+ log_debug "bup: backup finished"
return $retcode
}
# server_restore relies on output format of this function
-function bup_ls_dir() {
+function bup_ls() {
local backup_dir="$1"
bup -d "$(bup_local)" ls -r "$backup_dir" "$BACKUP_NAME" | sort -r
}
-function bup_ls_all() {
- for backup_dir in ${BACKUP_DIRS[*]}
- do
- echo "bup: backups in \"$backup_dir\":"
- bup -d "$(bup_local)" ls -r "$backup_dir" --human-readable -l "$BACKUP_NAME"
- done
-}
-
function bup_restore() {
local remote="$1"
local snapshot="$2"
diff --git a/backends/tar.sh b/backends/tar.sh
index 6f7a3d6..6748ac9 100644
--- a/backends/tar.sh
+++ b/backends/tar.sh
@@ -5,7 +5,7 @@ function tar_init() {
# TODO: Make default .tar with optional bup
function tar_create_backup() {
- echo_debug "tar: backing up..."
+ log_debug "tar: backing up..."
local status
@@ -14,23 +14,23 @@ function tar_create_backup() {
tar -czf "$archname" "./$WORLD_NAME"
status=$?
if [ $status -ne 0 ]; then
- echo "tar: failed to save the world"
+ log_error "tar: failed to save the world"
rm "$archname" #remove (probably faulty) archive
return 1
fi
- echo_debug "tar: world saved to $archname, pushing it to backup directories..."
+ log_debug "tar: world saved to $archname, pushing it to backup directories..."
# 0 if could save to at least one backup dir
# TODO: make more strict?
local retcode=1
for backup_dir in ${BACKUP_DIRS[*]}
do
- echo "tar: backing up to \"$backup_dir\""
+ log_info "tar: backing up to \"$backup_dir\""
# scp acts as cp for local destination directories
scp "$archname" "$backup_dir/"
status=$?
if [ $status -ne 0 ]; then
- echo "tar: failed pushing to \"$backup_dir\", moving on"
+ log_error "tar: failed pushing to \"$backup_dir\", moving on"
else
retcode=0
fi
@@ -38,13 +38,13 @@ function tar_create_backup() {
rm "$archname"
- echo "tar: backup finished"
+ log_debug "tar: backup finished"
return $retcode
}
# server_restore relies on output format of this function
-function tar_ls_dir() {
+function tar_ls() {
local backup_dir="$1"
if [[ "$backup_dir" == *:* ]]; then
@@ -56,14 +56,6 @@ function tar_ls_dir() {
fi
}
-function tar_ls_all() {
- for backup_dir in ${BACKUP_DIRS[*]}
- do
- echo "tar: backups in ${backup_dir}:"
- tar_ls_dir "$backup_dir"
- done
-}
-
function tar_restore() {
local remote="$1"
local snapshot="$2"
@@ -73,7 +65,7 @@ function tar_restore() {
scp "$remote/$snapshot" "/tmp/"
status=$?
if [ $status -ne 0 ]; then
- echo "tar: failed to get archive from \"$remote/$snapshot\""
+ log_error "tar: failed to get archive from \"$remote/$snapshot\""
return 1
fi