Skip to content

Commit

Permalink
Improve entrypoint to handle backup restore on first start only (#77)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Sergey Nikolaev <[email protected]>
  • Loading branch information
donhardman and sanikolaev authored Feb 20, 2024
1 parent 931ace3 commit 3aec2ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 20 additions & 14 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3aec2ec

Please sign in to comment.