diff --git a/backup_db.ps1 b/backup_db.ps1 new file mode 100644 index 0000000..b2f923d --- /dev/null +++ b/backup_db.ps1 @@ -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 +} diff --git a/docker-compose.yml b/docker-compose.yml index 98006ca..1a82f9f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,4 +31,11 @@ services: volumes: client1_pgdata: - client1_odoo_data: \ No newline at end of file + 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