From 359acd674fd08e4ddcb7e7a7d026a134dea89912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vit=C3=B3ria=20Silva?= Date: Mon, 22 Dec 2025 22:54:11 +0000 Subject: [PATCH] Add script to restore Postgres from backup Introduces restore_postgres.sh for Endurain's demo instance to automate restoring the Postgres database from a backup, cleaning logs, pruning Docker images, and restarting containers. Includes usage instructions for scheduling via cron. --- aux_scripts/restore_postgres.sh | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 aux_scripts/restore_postgres.sh diff --git a/aux_scripts/restore_postgres.sh b/aux_scripts/restore_postgres.sh new file mode 100644 index 000000000..404cd2549 --- /dev/null +++ b/aux_scripts/restore_postgres.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# This script is used in Endurain's demo instance. + +# This script restores the Postgres database from a backup by replacing +# the current postgres data folder with a backup copy. It also stops +# and restarts the Docker containers (deleting current Docker images and +# fetching new ones) to ensure a clean state. Logs are also cleared. + +# To schedule this script to run daily at midnight, add the following line +# to your crontab (edit crontab with `crontab -e`): +# 0 0 * * * /opt/containers/endurain/restore_postgres.sh >> /opt/containers/endurain/restore_logfile.log 2>&1 + +# Exit on any error +set -e + +rm -f /opt/containers/endurain/restore_logfile.log + +echo "Stopping Docker containers..." +docker compose down + +echo "Removing unused Docker images..." +docker image prune -a -f + +echo "Removing postgres folder..." +rm -rf postgres + +echo "Removing app.log..." +rm logs/app.log + +echo "Copying postgres_backup to postgres..." +cp -R postgres_backup postgres + +echo "Starting Docker containers..." +docker compose up -d + +echo "Done! Containers are now running." \ No newline at end of file