The batch file backed up by PostgreSQL in Windows (modified version). When prompted to enter the password, the password can be automatically entered.

Source: Internet
Author: User

Find an article on the Internet titled PostgreSQL windows automatic backup script

Http://blog.it580.com/1910

 

 

I thought it was good. After a try, I found that the execution of the batch processing file was stopped and I was prompted to enter the password.

> Pg_dump-u Postgres-W database1> C:/backup.tar
> Password:

 

The method for automatically entering the password is found, and the modification is as follows:

 

Echo off <br/> REM function: PostgreSQL Windows platform automatic backup script <br/> REM creates a directory in the Backup Directory D:/backup in the next month, save the daily backup file of the current month in the monthly directory <br/> REM runs echo % date % on the command line before backup to ensure that the date format is yyyy-mm-dd, if not, go to the control panel to modify the date format in the region and language options. <Br/> REM Author: David Pan <br/> REM Date: 2009-02-19 </P> <p> @ set filename = % Date :~ 0, 10%. Backup <br/> @ set dirname = % Date :~ 0, 7% </P> <p> REM % dirname % * removes spaces after dirname </P> <p> @ set pgpath = C: /program files/PostgreSQL/8.4/bin </P> <p> If REM is set to No. 1 on the current day, a new month directory is created. <br/> @ if % Date :~ 8, 2% = 01 (md d:/backup/"% dirname % ") </P> <p> If REM does not have a directory for the current month, create a directory for the current month <br/> @ if not exist D:/backup/"% dirname %" (md d: /backup/"% dirname %") </P> <p> REM executes the Backup Task and backs up the databasename database. Replace version with your pgsql version, or modify it based on the location of your pg_dump file. <Br/> original REM statement <br/> REM "% pgpath %/pg_dump.exe"-I-H localhost-P 5432-u Postgres-f c-B-v-F "D: /backup/% dirname %/% filename % "database1 </P> <p> REM outputs the password script. The disadvantage is that the password is exposed obviously (the method I found to automatically enter the password) <br/> echo set PWS = wscript. createobject ("wscript. shell ")> % Temp %/PWS. vbs <br/> echo PWS. sendkeys "123 {enter}" >>% TEMP %/PWS. vbs </P> <p> REM executes the script to automatically enter the password (the method for automatically entering the password I found) <br/> wscript % Temp %/PWS. vbs & "% pgpath %/pg_dump.exe"-I-H Localhost-P 5432-u Postgres-f c-B-v-F "D: /backup/% dirname %/% filename % "benshop </P> <p> REM Delete script <br/> Del % Temp %/PWS. vbs </P> <p> REM packs the backup file into RAR format and deletes the original backup file. (Ensure that you have installed WinRAR. If you have not installed it in the default directory, modify the path according to the location of the WinRAR file.) <br/> @ if exist D: /backup/"% dirname %/% filename %" ("% ProgramFiles %/WinRAR" a-DF "D:/backup/% dirname %/%filename%.rar" "D: /backup/% dirname %/% filename % ") </P> <p> REM automatically deletes the backup before January 1, March, and determines Based on the creation date <br/> @ if % Date: ~ 8, 2% = 25 (for/F "Skip = 3" % A in ("DIR/B/AD/O:-d:/backup ") do @ if exist D:/backup/% a rd/S/q D:/backup/% A) </P> <p> @ echo on

------------------------------------------------------------------------

You do not need to enter a password when checking the information on the Internet. You can set a trust for an IP address in this way.

I am prompted that the password is mainly my pg_mirror.conf

Set the local password to MD5 authentication.

----------------------------------------------------------------------------
# Type Database User CIDR-ADDRESS Method

# IPv4 local connections:
Host All all 127.0.0.1/32 MD5

 

-----------------------------------------------------------------------------

 

In this case, you do not need to enter the password for the local backup (restart the service after the change)

----------------------------------------------------------------------------
# Type Database User CIDR-ADDRESS Method

# IPv4 local connections:
Host All all 127.0.0.1/32 Trust

 

-----------------------------------------------------------------------------

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.