Skip to content

Commit e92121d

Browse files
committed
Don't allow restore if services are running
1 parent 8fc6dde commit e92121d

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Once configured, the following commands are available:
301301
| --- | --- |
302302
| `/usr/share/openhexa/openhexa.sh backup` | Back up the PostgreSQL cluster, workspace files, Forgejo data and `.env` snapshot. |
303303
| `/usr/share/openhexa/openhexa.sh backup-status` | Show the duplicity `collection-status` for both the `workspaces` and `forgejo` backends. |
304-
| `/usr/share/openhexa/openhexa.sh restore` | Restore the latest backup. We advise stopping the service before a full restore. |
304+
| `/usr/share/openhexa/openhexa.sh restore` | Restore the latest backup. This requires stopping the services before a full restore. |
305305

306306
After a restore, an `openhexa-env.bak` file is left next to the workspace data:
307307
compare it with the live `.env` to make sure `ENCRYPTION_KEY`, `SECRET_KEY` and

script/openhexa.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,21 @@ function perform_restore() {
266266
require_backup_config || return 1
267267
(
268268
load_env
269-
local location passphrase dumpfile_path envcopy_path pgpassfile psql_exit_code psql_result
269+
local location passphrase dumpfile_path envcopy_path pgpassfile psql_exit_code psql_result running_services
270270
location=$(get_backup_config LOCATION)
271271
passphrase=$(get_backup_config PASSPHRASE)
272272

273+
echo -n "Check that no OpenHEXA services are running ... "
274+
running_services=$(number_of_running_services)
275+
if ((running_services > 0)); then
276+
echo "KO"
277+
echo "Refusing to restore while ${running_services} service(s) are running."
278+
echo "Active connections would block DROP DATABASE during the dump replay."
279+
echo "Stop everything first with: ./script/openhexa.sh stop"
280+
return 1
281+
fi
282+
echo "OK"
283+
273284
echo -n "Keep a copy of the workspace target ... "
274285
mv "${WORKSPACE_STORAGE_LOCATION}" "${WORKSPACE_STORAGE_LOCATION}-$(date -Iseconds)"
275286
mkdir "${WORKSPACE_STORAGE_LOCATION}"

0 commit comments

Comments
 (0)