From 3aec2ec5b2c0ec547cdaf00e389fb25ee754772a Mon Sep 17 00:00:00 2001 From: Don Hardman <59067742+donhardman@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:39:59 +0700 Subject: [PATCH] Improve entrypoint to handle backup restore on first start only (#77) --------- Co-authored-by: Sergey Nikolaev --- README.md | 4 ++-- docker-entrypoint.sh | 34 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index db1279f..13fb79d 100644 --- a/README.md +++ b/README.md @@ -341,10 +341,10 @@ Inside this folder, you will find your backup. To restore your full backup on startup, you need to mount your backup to the `/docker-entrypoint-initdb.d` folder. + Please note that you should mount the content of your backup, not the backup folder itself (e.g., `backup-202307..`). -The restore process temporarily prevents the regular `searchd` start. -If you wish to avoid this behavior, you can set the flag `-e START_AFTER_RESTORE=true`. +The backup will be restored if the data directory is empty. Otherwise, it will be skipped, even if it's mounted on the second launch or any other time. Once the backup is restored, the daemon will start. ### Creating SQL dumps diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c6bf89e..b0fe50a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -241,26 +241,32 @@ _main() { fi BACKUP_INIT_FOLDER="/docker-entrypoint-initdb.d" + INITED="" + for f in /var/lib/manticore/*; do + INITED=1 + break + done if [ -f "${BACKUP_INIT_FOLDER}/versions.json" ]; then + if [ -n "$INITED" ]; then + echo "Warning: Backup is available for restore, but it's being skipped because it's already initialized or the data directory is not empty." + else + if [ ! -s "/usr/bin/manticore-executor" ]; then + echo -e "${RED}Can't run manticore-backup. Use env. var. EXTRA=1 to install the missing packages.${NC}" + exit 1 + fi - if [ ! -s /usr/bin/manticore-executor ]; then - echo -e "${RED}Can't run manticore-backup. Use env. var. EXTRA=1 to install the missing packages.${NC}" + # Check if manticore-backup is installed + if ! command -v manticore-backup > /dev/null; then + echo -e "${RED}manticore-backup isn't installed${NC}" exit 1 - fi - - [[ $(which manticore-backup) ]] || \ - { echo -e "${RED}Manticore backup isn't installed${NC}"; exit 1; } - - find ${BACKUP_INIT_FOLDER}/config -type f -exec sh -c 'rm -f "${1#/docker-entrypoint-initdb.d/config}"' sh {} \; - find ${BACKUP_INIT_FOLDER}/state -type f -exec sh -c 'rm -f "${1#/docker-entrypoint-initdb.d/state}"' sh {} \; + fi - manticore-backup --version - manticore-backup --force --backup-dir='/' --restore='docker-entrypoint-initdb.d' + find ${BACKUP_INIT_FOLDER}/config -type f -exec sh -c 'rm -f "${1#/docker-entrypoint-initdb.d/config}"' sh {} \; + find ${BACKUP_INIT_FOLDER}/state -type f -exec sh -c 'rm -f "${1#/docker-entrypoint-initdb.d/state}"' sh {} \; - if [ -z "$START_AFTER_RESTORE" ]; then - echo -e "${GREEN}Dump successfully restored.${NC} Run container again without mounting anything to docker-entrypoint-initdb.d" - exit 0 + manticore-backup --version + manticore-backup --force --backup-dir='/' --restore='docker-entrypoint-initdb.d' fi fi