From cd32e794b00c04a5b969fd0292c7764e32e25863 Mon Sep 17 00:00:00 2001 From: TheMightyV Date: Sun, 2 Jan 2022 19:52:03 +0100 Subject: converted spaces to tabs, moved tar and bup backends to backend directory --- backends/bup.sh | 23 +++++++++++++++++++ backends/tar.sh | 14 ++++++++++++ server.sh | 71 ++++++++++++++------------------------------------------- serverconf.sh | 5 ++-- 4 files changed, 56 insertions(+), 57 deletions(-) create mode 100644 backends/bup.sh create mode 100644 backends/tar.sh diff --git a/backends/bup.sh b/backends/bup.sh new file mode 100644 index 0000000..83e4e98 --- /dev/null +++ b/backends/bup.sh @@ -0,0 +1,23 @@ +function create_bup_backup() { + BACKUP_DIR="mc-backups" + CUR_BACK_DIR="mc-backups/$CUR_YEAR" + + if [ ! -d "$CUR_BACK_DIR" ]; then + mkdir -p "$CUR_BACK_DIR" + fi + + bup -d "$CUR_BACK_DIR" index "$WORLD_NAME" + status=$? + if [ $status -eq 1 ]; then + bup -d "$CUR_BACK_DIR" init + bup -d "$CUR_BACK_DIR" index "$WORLD_NAME" + fi + + bup -d "$CUR_BACK_DIR" save -n "$BACKUP_NAME" "$WORLD_NAME" + + echo "Backup using bup to $CUR_BACK_DIR is complete" +} + +function ls_bup() { + bup -d "mc-backups/${CUR_YEAR}" ls "mc-sad-squad/$1" +} diff --git a/backends/tar.sh b/backends/tar.sh new file mode 100644 index 0000000..4d7ff36 --- /dev/null +++ b/backends/tar.sh @@ -0,0 +1,14 @@ +# TODO: Make default .tar with optional bup +function tar_create_backup() { + ARCHNAME="backup/$WORLD_NAME-backup_`date +%d-%m-%y-%T`.tar.gz" + tar -czf "$ARCHNAME" "./$WORLD_NAME" + + if [ ! $? -eq 0 ] + then + echo "TAR failed. No Backup created." + rm $ARCHNAME #remove (probably faulty) archive + return 1 + else + echo $ARCHNAME created. + fi +} diff --git a/server.sh b/server.sh index 7e453a7..0bed9af 100755 --- a/server.sh +++ b/server.sh @@ -8,6 +8,9 @@ else exit 1 fi +source "backends/tar.sh" +source "backends/bup.sh" + function backup_hook_example { bup -d $CUR_BACK_DIR ls -l $BACKUP_NAME/latest/var/minecraft } @@ -81,7 +84,7 @@ function server_running() { ps -p $(cat $PIDFILE) > /dev/null return fi - + false } @@ -119,7 +122,7 @@ function server_backup_safe() { send_cmd "save-off" send_cmd "save-all flush" echo "Waiting for save... If froze, run /save-on to re-enable autosave!!" - + sleep 1 while [ $(tail -n 3 "$LOGFILE" | grep -c "Saved the game") -lt 1 ] do @@ -133,7 +136,7 @@ function server_backup_safe() { else create_backup_archive fi - + local RET=$? echo "Re-enabling auto-save" @@ -162,42 +165,6 @@ function server_backup_unsafe() { fi } -function create_bup_backup() { - BACKUP_DIR="mc-backups" - CUR_BACK_DIR="mc-backups/$CUR_YEAR" - - if [ ! -d "$CUR_BACK_DIR" ]; then - mkdir -p "$CUR_BACK_DIR" - fi - - - bup -d "$CUR_BACK_DIR" index "$WORLD_NAME" - status=$? - if [ $status -eq 1 ]; then - bup -d "$CUR_BACK_DIR" init - bup -d "$CUR_BACK_DIR" index "$WORLD_NAME" - fi - - bup -d "$CUR_BACK_DIR" save -n "$BACKUP_NAME" "$WORLD_NAME" - - echo "Backup using bup to $CUR_BACK_DIR is complete" -} - -# TODO: Make default .tar with optional bup -function create_backup_archive() { - ARCHNAME="backup/$WORLD_NAME-backup_`date +%d-%m-%y-%T`.tar.gz" - tar -czf "$ARCHNAME" "./$WORLD_NAME" - - if [ ! $? -eq 0 ] - then - echo "TAR failed. No Backup created." - rm $ARCHNAME #remove (probably faulty) archive - return 1 - else - echo $ARCHNAME created. - fi -} - function backup_running() { systemctl is-active --quiet mc-backup.service } @@ -210,30 +177,26 @@ function server_backup() { force=$1 if [ "$force" = "true" ]; then - if backup_running; then - echo "A backup is running. Aborting..." - return - fi - else - if fbackup_running; then - echo "A force backup is running. Aborting..." - return - fi + if backup_running; then + echo "A backup is running. Aborting..." + return + fi + else + if fbackup_running; then + echo "A force backup is running. Aborting..." + return + fi fi - if server_running; then + if server_running; then server_backup_safe "$force" - else + else server_backup_unsafe fi exit } -function ls_bup() { - bup -d "mc-backups/${CUR_YEAR}" ls "mc-sad-squad/$1" -} - #cd $(dirname $0) case $1 in diff --git a/serverconf.sh b/serverconf.sh index cb88dc4..25ba16e 100644 --- a/serverconf.sh +++ b/serverconf.sh @@ -1,10 +1,10 @@ # serverconf.sh -# configuration file for server.sh minecraft server +# configuration file for server.sh minecraft server # management script #CONFIG JRE_JAVA="java" -JVM_ARGS="-Xms4096M -Xmx6144M" +JVM_ARGS="-Xms4096M -Xmx6144M" JAR="fabric-server-launch.jar" JAR_ARGS="-nogui" @@ -20,4 +20,3 @@ USE_BUP="NO" #Constants CUR_YEAR=`date +"%Y"` - -- cgit v1.2.3