Silencer001
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.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, and you might want to change the postgre password now ...