From c0b0ce887459284bcd161fd60601a56a19fe1edb Mon Sep 17 00:00:00 2001 From: gw3000 Date: Sun, 30 Jul 2023 13:31:13 +0200 Subject: [PATCH] Backup and Restore scripts --- .gitignore | 1 + bin/backupDB | 7 +++++++ bin/restoreDB | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100755 bin/backupDB create mode 100755 bin/restoreDB diff --git a/.gitignore b/.gitignore index a131400..fe740bd 100644 --- a/.gitignore +++ b/.gitignore @@ -173,6 +173,7 @@ traefik-public-certificates # Postgres Data postgres_data +postgres_backup # Prestatic Collections app/staticfiles diff --git a/bin/backupDB b/bin/backupDB new file mode 100755 index 0000000..197e0fd --- /dev/null +++ b/bin/backupDB @@ -0,0 +1,7 @@ +#!/bin/bash + +# CREATE DATABASE DUMP OF DB_FBF. +docker exec django_fbf-db-1 /bin/bash -c "/usr/local/bin/pg_dump -U fbf -d db_fbf > /backup/fbf-backup.sql" + +# cOPY AND COMPRESS DUMP FILE. +docker exec django_fbf-db-1 /bin/bash -c "cd /backup && /bin/tar -czvf fbf-backup__$(date '+%Y-%m-%d').tar.gz fbf-backup.sql" diff --git a/bin/restoreDB b/bin/restoreDB new file mode 100755 index 0000000..e656144 --- /dev/null +++ b/bin/restoreDB @@ -0,0 +1,16 @@ +#!/bin/bash + +# STOP WEB CONTAINER TO KILL ALL SESSIONS. +docker stop django_fbf-web-1 + +# DROP THE DATABASE. +docker exec -it django_fbf-db-1 psql -U fbf -d postgres -c "DROP DATABASE db_fbf;" + +# CREATE THE DATABASE. +docker exec -it django_fbf-db-1 psql -U fbf -d postgres -c "CREATE DATABASE db_fbf;" + +# RESTORE THE DATABASE. +docker exec -it django_fbf-db-1 /usr/local/bin/psql -U fbf -d db_fbf -f /backup/fbf-backup.sql + +# START THE WEB CONTAINER. +docker start django_fbf-web-1