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.
This commit is contained in:
João Vitória Silva
2025-12-22 22:54:11 +00:00
parent 0797435d4e
commit 359acd674f

View File

@@ -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."