diff --git a/scripts/prod/CreateBackup.sh b/scripts/prod/CreateBackup.sh new file mode 100644 index 00000000..7ec8bd03 --- /dev/null +++ b/scripts/prod/CreateBackup.sh @@ -0,0 +1,49 @@ +# ====== Create database backup ========== +# WARNING! DO NOT RUN THIS FILE AUTOMATICALLY FROM REPOSITORY LOCATION! +# Create a copy in secure location @production host. Update backup scripts from repository manually +# ======================================== + +backupLocation="/home/admuser/backup" +pgUser="portal-admin" +pgDB="portal-db" +containerDB="portal-db" +containerBackend="portal-backend" + +dateFmt=$(date '+%Y-%m-%d') +destination="$backupLocation/$dateFmt" + +EnsureLocation() +{ + rm -rf $destination + mkdir $destination +} + +PostgreDump() +{ + dbDump="$destination/$dateFmt-db.dump" + docker exec $containerDB pg_dump \ + --username=$pgUser \ + --exclude-table=django_migrations \ + --format=custom \ + --dbname=$pgDB \ + > $dbDump +} + +DjangoDump() +{ + dataDump="$destination/$dateFmt-data.json" + docker exec $containerBackend \ + python manage.py dumpdata \ + --indent=2 \ + --exclude=admin.LogEntry \ + --exclude=sessions \ + --exclude=contenttypes \ + --exclude=auth.permission \ + > $dataDump + gzip --force $dataDump +} + +EnsureLocation +PostgreDump +DjangoDump +echo "Backup created at: $destination" \ No newline at end of file diff --git a/scripts/prod/LoadPostgreBackup.ps1 b/scripts/prod/LoadPostgreBackup.ps1 index 86e7e55b..b4c53fb3 100644 --- a/scripts/prod/LoadPostgreBackup.ps1 +++ b/scripts/prod/LoadPostgreBackup.ps1 @@ -4,7 +4,7 @@ # Input params $dataDump = "D:\DEV\backup\portal\2023-09-01\2023-09-01-db.dump" -$target = "local-portal-db" +$target = "dev-portal-db" $pgUser = "portal-admin" $pgDB = "portal-db"