PostgreSQL automatically backs up bitsCN.com in Windows
This article describes how to create a Windows batch processing file to automatically back up the PostgreSQL database. Background an automated system is required for my work on a PostgreSQL database project to perform backups every day. After some research, we decided to create a Windows batch processing file and add it to the Windows scheduled task. The following describes how to configure the first step: Download a batch file. Step 2: You can use a simple command (schtasks /? View help) or use a graphical interface (start-control panel-system and security-management tools-Task Scheduler) to run the task scheduler management tool, you can also double-click Taskschd in the % SYSTEMROOT %/System32 directory. msc to start it. Step 3: You can use a wizard or XML file to import information to create a basic task. For how to Create a wizard, see the task scheduler help. The following describes the Command Line Syntax: 1 schtasks/Create [/S [/U [/P [ ] 2 [/RU [/RP ]/SC [/MO ] [/D ] 3 [/M ] [/I ]/TN /TR [/ST ] 4 [/RI ] [{/ET |/DU } [/K] [/XML ] [/V1] 5 [/SD ] [/ED ] [/IT] [/Z] [/F]
View the help of this command: 1 schtasks/Create /?
If remote Task Scheduler management is disabled in Windows Firewall, file and print sharing are enabled, and the remote registry service is running, a V1 task is created on the remote computer even if the parameter V1 is not used. The V1 parameter indicates that a task is visible to the lower-level system. Run the code script: 01 @ ECHO OFF02 @ setlocal enableextensions @ cd/d "% ~ Dp0 "03 04 set pgpath = C:/" Program Files "/PostgreSQL/9.1/bin/05 set svpath = f: /06 set prjdb = demo07SET DBUSR = ipvs08for/F "TOKENS = 1, 2, 3 DELIMS =/" % I IN ('date/t ') do set d = % I-% j-% k09FOR/F "TOKENS = 1, 2, 3 DELIMS =:" % I IN ('Time/t ') do set t = % I % j % k10 11 SET DBDUMP = % PRJDB % _ % d % _ % t %. SQL @ ECHO OFF12 % PGPATH % pg_dump-h localhost-p 5432-U postgres % PRJDB %> % SVPATH % DBDUMP % 13 14 echo Backup Taken Complete % SVPATH % DBDUMP %
Initial value
- PGPATH-PostgreSQL path
- SVPATH-backup file path
- PRJDB-name of the database to be backed up
- DBUSR-database username
BitsCN.com