Background
in my job. An automated system is required on a project using the PostgreSQL database to perform backups on a daily basis. After some research, it is decided to create a Windows batch file and add it to the Windows Planning task.
The following are the specific steps:
How to configure
First step:
Download the batch file.
Step Two:
You can run the Task Scheduler management tool with a simple command (schtasks/? view Help) or a graphical interface (Start-Control Panel-system and security-management tools-Task Scheduler), and you can also use the%systemroot%\ System32 directory, double-click the Taskschd.msc to start it.
Step Three:
You can create basic tasks by using wizards or importing information through an XML file. Wizard How to create methods see Task Scheduler Help, below is a description of the following command line syntax:
schtasks/create [/S <system> [u <username> [P [<password>]]]
[/ru <username> [/RP < PASSWORD>]]/sc <schedule> [/mo <modifier>] [/D <day>] [
/M <months>] [/I <idletime ]/tn <taskname>/tr <taskrun> [/st <starttime>]
[/ri <interval>] [{/et <endtime> | /du <duration>} [/k] [/xml <xmlfile>] [/V1]]
[/sd <startdate>] [/ed <enddate>] [it] [/Z] [/F ]
To view this command help:
If remote task scheduling management is disabled in Windows Firewall and file and print sharing is enabled and the Remote Registry service is running, the remote computer will be created with a V1 task even if the parameter V1 is not used. The parameter V1 indicates that a task is visible to the underlying system.
Using code
script:
<a href= "http://my.oschina.net/echolee1987" target= "_blank" rel= "nofollow" > @ECHO </a> off
@setlocal Enableextensions<a href= "Http://my.oschina.net/duini" target= "_blank" rel= "nofollow" > @cd </a>/d "%~dp0"
SET pgpath=c:\ "program Files" \postgresql\9.1\bin\
Set svpath=f:\
set Prjdb=demo
set dbusr=postgres
for/f "tokens=1,2,3 delims=/"%%i in (' date/t ') do set d=% %i-%%j-%%k
for/f "tokens=1,2,3 delims=:"%%i in (' time/t ') do set t=%%i%%j%%k
set Dbdump=%prjdb%_%d%_%t%.sql< ; a href= "http://my.oschina.net/echolee1987" target= "_blank" rel= "nofollow" > @ECHO </a> off
%pgpath%pg_ Dump-h localhost-p 5432-u postgres%prjdb% >%svpath%%dbdump%
echo Backup taken Complete-%svpath%%dbdump%
Initial value
- Pgpath-postgresql Path
- Svpath-Backup file path
- Prjdb-The name of the database to be backed up
- DBUSR-Database user name