Automatic PostgreSQL backup tutorial in Windows and postgresql backup tutorial

Source: Internet
Author: User
Tags postgresql backup schtasks

Automatic PostgreSQL backup tutorial in Windows and postgresql backup tutorial

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 procedure is as follows:

How to configure
Step 1:
Download the 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 the wizard or XML file 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:
 

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] 

View the help of this command:
 

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.

Use 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=demoSET DBUSR=postgresFOR /F "TOKENS=1,2,3 DELIMS=/ " %%i IN ('DATE /T') DO SET d=%%i-%%j-%%kFOR /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-name of the database to be backed up
  • DBUSR-database username


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.