mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
wekan.database-restore and wekan.database-backup talked to whatever was on the database port and nothing else. After `snap stop wekan`, which the restore steps tell people to run, nothing is there; on a FerretDB snap the database is its own service that starting WeKan alone does not bring back. The tools then failed after a 30-second server-selection timeout with a driver topology dump naming neither the service nor its log. The new bin/database-ready asks bin/database-role which database holds the data, starts that service when nothing answers, waits for it, and when it still does not answer stops with the driver's own error and the `snap logs` / `snap services` commands that show the reason. A "permission denied" is explained as a security-policy denial on this system, not the database, with the journal command that names the rule. WeKan's own wait for FerretDB discarded the ping error, so its log said only "FerretDB not ready yet" for every cause. db-eval now prints why a command failed on stderr, and the wait's one-time hint shows it. The same hint suggested `snap set wekan database=mongodb`, a setting the configure hook removes, so that advice did nothing; it is gone. The backup script also sources its settings and passes the archive path quoted now, so a path with a space works. tests/snapDatabaseRestore.test.cjs runs both scripts in a stand-in snap: FerretDB or MongoDB started by role, a running database left alone, and, negatively, a database that never answers stopping the tool before it runs, with the error shown. A source guard requires both tools to wait for the database first. tests/ferretdbWaitTimeout.test.cjs now requires the ping error in the hint and rejects the removed setting. Not run inside an installed snap here. Thanks to fabiosalles and xet7 !
47 lines
1.8 KiB
Bash
Executable File
47 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
if [[ "$PATH" != *"$SNAP_INSTANCE_NAME"* ]]; then
|
|
export PATH="${PATH/\/snap\/wekan\//\/snap\/$SNAP_INSTANCE_NAME\/}"
|
|
fi
|
|
|
|
# get wekan/mongo settings
|
|
source "$SNAP/bin/wekan-read-settings"
|
|
|
|
# make sure we have set minimum env variables for locale
|
|
if [ -z "$LANG" ]; then
|
|
export LANG=en_US.UTF-8
|
|
fi
|
|
|
|
export LC_ALL=C
|
|
# If CPU does not support AVX, use Qemu that supports AVX.
|
|
# Migratemongo is at https://github.com/wekan/migratemongo
|
|
# and at directory /snap/${SNAP_NAME}/current/migratemongo/avx
|
|
# is bash scripts like mongod, mongosh check avx support and use Qemu if needed.
|
|
export PATH=$SNAP/migratemongo/avx:$SNAP/usr/bin:$SNAP/bin:$PATH
|
|
export LD_LIBRARY_PATH=$SNAP/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH
|
|
|
|
# start mongodb restore
|
|
if [[ $# -ne 1 ]]; then
|
|
echo "Usage: ${SNAP_INSTANCE_NAME:-wekan}.database-restore FULL-PATH-TO-BACKUP-FILENAME" >&2
|
|
exit 2
|
|
fi
|
|
|
|
archive=$1
|
|
if [[ ! -f "$archive" ]]; then
|
|
echo "Backup archive does not exist or is not a file: $archive" >&2
|
|
exit 2
|
|
fi
|
|
|
|
[ "x" == "x${MONGODB_BIND_IP}" ] && MONGODB_BIND_IP="127.0.0.1"
|
|
echo "using bind ip: $MONGODB_BIND_IP port: $MONGODB_PORT"
|
|
# #6746: the database is a service of its own and is stopped after `snap stop
|
|
# wekan`; start the one that holds the data and wait for it, or say why not.
|
|
source "$SNAP/bin/database-ready"
|
|
database_ready "$MONGODB_BIND_IP" "$MONGODB_PORT" || exit 1
|
|
# --drop: drop each collection before restoring to avoid IndexKeySpecsConflict
|
|
# when the dump's index specs differ from the existing index definitions
|
|
# (e.g. unique flag mismatch after a schema migration).
|
|
# Add --noIndexRestore instead of --drop if you need to preserve existing data
|
|
# and are happy to let WeKan rebuild indexes on next startup.
|
|
mongorestore --host "$MONGODB_BIND_IP" --port "$MONGODB_PORT" -d wekan --drop --gzip "--archive=$archive"
|