docker-apps/_instructions/restoring databases-psql.txt
2025-04-15 22:40:04 +02:00

55 lines
2.5 KiB
Plaintext

Precondition
------------
Destination database is newly created, i.e. completely empty, if not refer to "Clearing target database"
Preparation
-----------
If restoration is to made to postgres running in jailmaker/docker, ensure that docker config file has the following binding under systemd_nspawn_user_args.
On truenas shell enter: jlmkr edit docker
Edit systemd_nspawn_user_args setting to include:
--bind='/mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net:/mnt/migrate'
Backup file access
------------------
Postgres can access the backup file in at least two ways:
1. Copying the file to a folder in postgres container using docker cp, or
2. Mounting the /mnt/migrate folder in postgres container
Option 1. Copying the file to a folder in postgres container
------------------------------------------------------------
On truenas shell, open docker shell:
jlmkr shell docker
docker ps
Container list will be displayed, e.g.:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
572f221431ca vaultwarden/server:latest "/start.sh" 2 hours ago Up 2 hours (healthy) 80/tcp vaultwarden
adb7d77f22ee postgres:15 "docker-entrypoint.s…" 2 hours ago Up 2 hours (healthy) 5432/tcp pg_vaultwarden
Note the postgres CONTAINER ID, i.e. adb7d77f22ee:
docker cp /mnt/migrate adb7d77f22ee:/var/backups
Option 2. Mounting the migrate folder in postgres container
-----------------------------------------------------------
Edit postgres docker-compose file and a mount under services.postgres.volumes: - /mnt/migrate:/var/backups
Rebuild postgres container
Restore vaultwarden database using psql
--------===========--------------------
In docker shell:
docker stop vaultwarden
docker exec -it pg_vaultwarden sh
psql -U vaultwarden -d vaultwarden < /var/backups/2024-08-27/databases/vaultwarden-backup.sql
exit (exit pg_vaultwarden shell)
docker start vaultwarden
Clearing target database
------------------------
The restore process requires a completely empty database, so if this is an existing database it needs to be cleared first.
If there is any data present that might need to be recovered in future, backup the target database first, before following the steps hereafter.
We will delete then recreate database:
In docker shell, docker stop vaultwarden
Use pgadmin to delete Servers -> vaultwarden -> vaultwarden database
Create new database with same name, i.e. vaultwarden
In docker shell, docker start vaultwarden