From 2f6ea327d160ee3a831387fd4d7a8a10f73f9cd2 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 3 May 2021 18:00:27 -0500 Subject: [PATCH] Number of package backups can be configured with PACKAGE_BACKUP_KEEP #150 --- README.md | 1 + bedrock-entry.sh | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a70123..c784cfd 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ For Minecraft Java Edition you'll need to use this image instead: bedrock server process - `GID` (default derived from `/data` owner) : can be set to a specific group ID to run the bedrock server process +- `PACKAGE_BACKUP_KEEP` (`2`) : how many package backups to keep ### Server Properties diff --git a/bedrock-entry.sh b/bedrock-entry.sh index b117372..ce16890 100755 --- a/bedrock-entry.sh +++ b/bedrock-entry.sh @@ -83,7 +83,7 @@ if [ ! -f "bedrock_server-${VERSION}" ]; then fi # remove only binaries and some docs, to allow for an upgrade of those - rm -rf bedrock_server *.so release-notes.txt bedrock_server_how_to.html valid_known_packs.json premium_cache 2> /dev/null + rm -rf bedrock_server bedrock_server-* *.so release-notes.txt bedrock_server_how_to.html valid_known_packs.json premium_cache 2> /dev/null bkupDir=backup-pre-${VERSION} # fixup any previous interrupted upgrades @@ -97,6 +97,15 @@ if [ ! -f "bedrock_server-${VERSION}" ]; then fi done + # remove old package backups, but keep PACKAGE_BACKUP_KEEP + if (( ${PACKAGE_BACKUP_KEEP:=2} >= 0 )); then + shopt -s nullglob + for d in $( ls -td1 backup-pre-* | tail +$(( PACKAGE_BACKUP_KEEP + 1 )) ); do + echo "Pruning $d" + rm -rf $d + done + fi + # Do not overwrite existing files, which means the cleanup above needs to account for things # that MUST be replaced on upgrade unzip -q -n ${TMP_ZIP}