User Manual

07.28.2025

MANUAL

FAQ: PostgreSQL database backup and restore procedure (using Docker)

## Prerequisites 1. This procedure is for the Pleasanter database (Implem.Pleasanter) built in Docker using the installation procedure in the user manual. 1. For the backup and restore procedure of a PostgreSQL database installed directly on Linux, please refer to "[FAQ: PostgreSQL database backup and restore procedure](/en/manual/faq-postgresql-backup-restore)". ## Overview If you want to restore to the same environment as the environment in which the backup was taken, follow the procedure below. In this procedure, the dump file is also output to a folder on the host side so that it can be saved and used outside the container. ## Operation Procedure 1. Backup 2. Restore ### 1. Backup 1. Run the following command to stop the DB container. ``` docker compose stop db ``` 2. Add information about the folder and volume where the backup file will be output to compose.yaml. In this procedure, it will be obtained under the /backup directory. ```text services: db: volumes: - ./backup:/backup  ←Add this description. ``` 3. Create a folder on the host side to get the backup file. ![image](https://pleasanter.org/binaries/340e3e3b39b749a1821aa299ca1d740c) 4. Execute the following command to add the /backup directory to the volume and recreate and restart. ``` docker compose up -d db ``` 5. Execute the following command to enter the DB container. ``` docker compose exec -u postgres db bash ``` 6. Execute the command to get the backup file. ``` pg_dump -Fc Implem.Pleasanter > /backup/Implem.Pleasanter.dump ``` 7. Execute the following command to confirm that the backup file was created in the container directory. ``` ls -la /backup/Implem.Pleasanter.dump ``` Execution result example `-rw-r--r-- 1 postgres postgres 648849 May 08 06:25 /backup/Implem.Pleasanter.dump` 8. Confirm that the backup file was created in the host folder. ![image](https://pleasanter.org/binaries/8abd37bbadf54869a0f1d8f0a62ee4f4) 9. Exit the DB container. ``` exit ``` ### 2. Restore 1. Run the following command to stop only the pleasanter container. ``` docker compose stop pleasanter ``` 2. Run the following command to enter the DB container. ``` docker compose exec -u postgres db bash ``` 3. Take a backup using the same command as the backup procedure above so that you can switch back after the restore. ``` pg_dump -Fc Implem.Pleasanter > [Output path/file name of the backup file to be taken before the restore] ``` 4. Delete and recreate the database (Implem.Pleasanter) using SQL. ``` psql -U postgres -c 'drop database "Implem.Pleasanter";' psql -U postgres -c 'create database "Implem.Pleasanter";' ``` 5. Run the restore command. In this procedure, we will restore the database using the backup file in the /backup directory. ``` pg_restore -d Implem.Pleasanter /backup/Implem.Pleasanter.dump ``` 6. Exit the DB container. ``` exit ``` 7. Restart the pleasanter container. ``` docker compose start pleasanter ```
TOP
このページをシェアする
記載された商品名、各製品名は各社の登録商標または商標です。 © Implem Inc.