Automatically back up PostgreSQL tutorials in Windows-database other

Source: Internet
Author: User
Tags postgresql schtasks

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:

Schtasks/create/?

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.