oneuptime/restore.sh

24 lines
997 B
Bash
Raw Normal View History

2023-07-31 00:48:48 +00:00
# This file takes last 30 days backup. Make sure you run this file at least once/day.
2022-12-12 09:55:30 +00:00
# The backup will be in the format of db-(date of the month).backup
# Before the backup, please make sure DATABASE_RESTORE_* ENV vars in config.env is set properly.
2023-04-29 12:59:34 +00:00
# IMPORTANT: Before restore, all database containers should be stopped.
# Restoring to a new database,
# Delete existing db.
# Create a new db.
# Make sure you have created the database and user before running this script.
2022-12-12 09:55:30 +00:00
export $(grep -v '^#' config.env | xargs)
2022-12-30 14:01:49 +00:00
echo "Starting restore...."
2022-12-31 11:24:00 +00:00
git pull
2022-12-31 11:23:17 +00:00
sudo docker run --net=host --rm \
2022-12-12 09:55:30 +00:00
--env-file config.env \
--add-host=host.docker.internal:host-gateway \
2022-12-12 09:55:30 +00:00
--volume=$(pwd)$DATABASE_RESTORE_DIRECTORY:/var/lib/postgresql/data \
postgres:latest /usr/bin/pg_restore --dbname=postgresql://$DATABASE_RESTORE_USERNAME:$DATABASE_RESTORE_PASSWORD@$DATABASE_RESTORE_HOST:$DATABASE_RESTORE_PORT/$DATABASE_RESTORE_NAME /var/lib/postgresql/data/$DATABASE_RESTORE_FILENAME
2022-12-30 14:01:49 +00:00
echo "Restore Completed"