Skip to content

Commit

Permalink
Change the logic to restore on the first launch from the backup if pr…
Browse files Browse the repository at this point in the history
…esents, start always and update Readme
  • Loading branch information
donhardman committed Feb 16, 2024
1 parent dd2febd commit 19207ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,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 daemon wasn't initialized before (first start). 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

Expand Down
33 changes: 19 additions & 14 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -241,29 +241,34 @@ _main() {
fi

BACKUP_INIT_FOLDER="/docker-entrypoint-initdb.d"
INIT_PATH="/var/lib/manticore/.inited"

if [ -f "${BACKUP_INIT_FOLDER}/versions.json" ]; then
if [ -f "$INIT_PATH" ]; then
echo "Warning: Backup is available for restore, but it's being skipped because it's already initialized."
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

# Mark as initialized
touch "$INIT_PATH"

exec "$@"
}

Expand Down

0 comments on commit 19207ac

Please sign in to comment.