Link to home
Start Free TrialLog in
Avatar of Silencer001
Silencer001Flag for Belgium

asked on

Backup of postgresql database with batch

Hi,

I want to create a batch file that backup our postgresql database schema. But I also want it to look in the backup folder how many files there are. If there are already 4 backup files, I want the batch file to delete 1. So the maximum of backup files has to be 4.

Below you find the code that I already have. I works, but I want to add that there can only be a maximum of 4 backupfiles.

 @echo off
   for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
     set dow=%%i
     set month=%%j
     set day=%%k
     set year=%%l
   )
   set datestr=%month%_%day%_%year%
   echo datestr is %datestr%
    
   set BACKUP_FILE=C:\postgresql_backup\backup_archx_%datestr%.backup
   echo backup file name is %BACKUP_FILE%
   SET PGPASSWORD=P0stgr3s
   echo on
   postgres\bin\pg_dump -i -h localhost -p 5432 -U postgres -F c -v -f %BACKUP_FILE% -n archx archx

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oBdA
oBdA

Oh, and you might want to change the postgre password now ...