Solved

Windows PowerShell - BackUp Postgre Dbase

Posted on 2009-03-30
4
1,736 Views
Last Modified: 2012-08-13
Hi,

I would like to ask if anyone knows how to backup postgre dbase using windows powershell and automate it to be done once a month.

Thanks.
0
Comment
Question by:openaccount1
  • 2
4 Comments
 
LVL 61

Expert Comment

by:gheist
ID: 24023578
Powershell does nothing once a month. You need another scheduler. PostgreSQL really does not care if pg_dumpall is ran from powershell or from cmd file or from atsvc directly.
0
 

Author Comment

by:openaccount1
ID: 24037145
ok say we use windows scheduler for the schedule. How can we backup our Dbases? Our service provider says that we can use the code below as a sample but I do not know anything about powershell. Can you explain the code below and how we can use it with windows scheduler?


set-item -force -path env:PGPASSWORD -value actualpassword
 

$pgdbs = "db1","db2","db3"
 

Foreach ($db in $pgdbs) {
 

                & 'C:\Program Files\PostgreSQL\8.3\bin\pg_dump.exe' -Fc -U username -f "path-to-backup-temp" $db
 

                remove-item "path-to-permanentbackup\pgdump$db"
 

                move-item "path-to-permanentbackup\pgdump$db" "path-to-backup-temp\pgdump$db"
 

}

Open in new window

0
 
LVL 61

Accepted Solution

by:
gheist earned 500 total points
ID: 24038257
It backs up all $pgdbs in background in parallel.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now