forked from alaguraj/odoo-testing-addons
add PowerShell script for database backups and include restore instructions in docker-compose.yml.
This commit is contained in:
parent
623a38d672
commit
2d0f11526d
25
backup_db.ps1
Normal file
25
backup_db.ps1
Normal file
@ -0,0 +1,25 @@
|
||||
# Odoo Database Backup Script
|
||||
# This script dumps the Postgres database from the Docker container
|
||||
|
||||
# 1. Create backup directory if it doesn't exist
|
||||
$BackupDir = "d:\Odoo\backups"
|
||||
if (!(Test-Path -Path $BackupDir)) {
|
||||
New-Item -ItemType Directory -Path $BackupDir
|
||||
}
|
||||
|
||||
# 2. Define Backup Filename with Timestamp
|
||||
$Date = Get-Date -f 'yyyy-MM-dd_HHmm'
|
||||
$Filename = "db_backup_$Date.sql"
|
||||
$FullPaths = Join-Path -Path $BackupDir -ChildPath $Filename
|
||||
|
||||
Write-Host "Starting backup to $FullPaths..." -ForegroundColor Cyan
|
||||
|
||||
# 3. Execute pg_dump inside the container
|
||||
# We use --clean to include 'DROP TABLE' statements for easier restoration
|
||||
docker exec odoo_client1_db pg_dump -U odoo -d postgres --clean > $FullPaths
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "✅ Backup successfully created: $Filename" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "❌ Backup failed! Please ensure docker-compose is running." -ForegroundColor Red
|
||||
}
|
||||
@ -31,4 +31,11 @@ services:
|
||||
|
||||
volumes:
|
||||
client1_pgdata:
|
||||
client1_odoo_data:
|
||||
client1_odoo_data:
|
||||
|
||||
|
||||
# backups:
|
||||
# .\backup_db.ps1
|
||||
|
||||
# Team Members – Restore
|
||||
# cat d:\Odoo\backups\YOUR_BACKUP_FILE.sql | docker exec -i odoo_client1_db psql -U odoo -d postgres
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user