|
PostgreSQL Books Friday, January 18. 2008Setting up PgAgent and Doing Scheduled Backups![]()
Comments
Display comments as
(Linear | Threaded)
This seems a really cool addition to PgAdmin III. Congratulations and thank you!
Very good post.
I just missed some information about setting up the daily backup job with the local authorization set to password on Windows. Passing the password to pgAgent with password=**** is not sufficient (and not save), as pg_dump requires a password too! This is not easy to detect, as pgAgent just waits for infinity. So setting the password in %APPDATA%\postgresql\pgpass.conf finally solved the issue.Now my db will get its daily backup Thank you.
How to config pgpass.conf and what is it's content?
I use PostgreSQL 8.1 so i dun see that file? Can you help me?
Each line is a separate connection option something like
localhost:5432:*:postgres:passwordhere Its documented here for 8.1 http://www.postgresql.org/docs/8.1/interactive/libpq-pgpass.html
Thx so much!! I Can handle it now!
But up to now, i can't run this batch with pgAgent, actually i did as this post I use it with Windows Schedule and Linux Crontab --> it's ok
in the Linux script in this topic, when you want to backup more or less database/schema you must reedit the script, it's so inconvenient. I find out the way easier to manage what you backup. I hope it will be usefull. See my Script:
#!/bin/bash #backup directory can be a file server share that the PgAgent daemon account has access to BACKUPDIR="/any/where/you/want" PGHOST="127.0.1.1" PGUSER="postgres" PGBIN="/where/your/pg/is/bin" thedate=`date --date="today" +%Y%m%d%H` themonth=`date --date="today" +%Y%m` # Logging the day you backup echo -e "\n\n\t\t`date --date="today" +%Y-%m-%d`\n" >> $BACKUPDIR/backup_log.log # Read data from list file note that ur list file contain many line. Each line have format : #database1|schema1 #database2|schema2 #btw if you want to separate by other symbols, you must remember to change the symbol at the IFS below. ^_^ #then backup data while read line do echo $line > temp_line while IFS='|' read db sch do $PGBIN/pg_dump -i -h $PGHOST -U $PGUSER -n $sch > $BACKUPDIR/$sch-$thedate.dump $db echo "`date --date="today" +%H:%M` Dump schema $sch in database $db of host $PGHOST" >> $BACKUPDIR/backup_log.log #done done < temp_line done < list.txt # delete temp file rm -f temp_line #this section deletes the previous month of same day backup except for the full server backup rm -f $BACKUPDIR/*`date --date="-2 day" +%Y%m%d`*.dump exit 0
Help!.
I did every thing you say and still can't run any job. Untill de job is shown in the panel, when I press "Run Now" nothing happens. Here is what I did: 1- create plpgsql languaje. 2- Run the script to create the schema 3- set the password in the user profile 4- install de agent services. 5- go to pgadmin 6- create new job as is shown 7- press "run now" 8- get confused when nothing happens. I have postgrres 8.3 in windows PC Thanks four your help. Regards, Miguel Maneiro
Miguel,
Did you verify to make sure the PostgreSQL Agent service is running in windows services. Sometimes it installs, but doesn't start. If the service isn't started, then clicking run in PgAdmin III won't do anything. The other possibility is that the postgres account the service is running under has no access or your .pgpass file does not exist or is invalid. To get around all of that - the simplest way is to allow localhost access without password (which on a box you control and only you or admins log into is fairly safe) You can set this by unremarking out the line (e.g. get rid of the #) next to the line that reads host all all 127.0.0.1/32 trust (or adding it if it doesn't exist) you can also do it via PgAdmin III by 1) click on server 2) Tools->Server Configuration -> pg_hba.conf and putting a check box on that line or adding a line like that. (note that you may not see this option if you do not have the adminpack.sql installed which is normally located in Program files\PostgreSQL\contrib\adminpack.sql (just run in postgres db) Hope that helps, Regina
Just in case if somebody is wondering why the Linux script doesn't work as it is - typos!
$PGBIN/pg_dumpall -h $PGHOST -U $PGUSER | gzip > $BACKUP_DIR/fullbackup-$themonth.sql.gz should be $PGBIN/pg_dumpall -h $PGHOST -U $PGUSER | gzip > $BACKUPDIR/fullbackup-$themonth.sql.gz $PGBIN/pg_dump -i -h $PG_HOST -U $PGUSER -F c -b -v -f $BACKUPDIR/$db-$thedate.compressed $db should be $PGBIN/pg_dump -i -h $PGHOST -U $PGUSER -F c -b -v -f $BACKUPDIR/$db-$thedate.compressed $db
Here is yet another script solution, using Python. I have this on a Windows machine tucked on a server. I just need to double-click it when I think it is a good time to do a backup (typically once in the morning and once in the afternoon).
#!/usr/bin/env python import os from datetime import date # Customize these: backupdir = r'\\Nas1\Documents\MyDB\backup' host = '192.168.123.248' dbname = 'mydb' user = raw_input('Username>') dateStr = date.today().isoformat() ver = 'a' while True: name = 'MyDB_'+dateStr+ver+'.backup' fullpath = os.path.join(backupdir,name) if ver == 'z': raise Exception, 'Possible file names a-z have been used!' elif os.path.isfile(fullpath): ver = chr(ord(ver)+1) # increment letter else: # file does not exist, go ahead and use it break cmd = 'pg_dump --ignore-version --host=%s --username=%s --format=c --blobs --verbose --file="%s" %s'%\ (host, user, fullpath, dbname) print 'cmd:', cmd res = os.system(cmd) print 'done:', res raw_input() # pause at end for people that double-click the script
Host - Windows XP SP2
PostgreSQL 8.2.9 PgAgent is installed and running as service Problem - in PGAdminIII, i setup the job as listed and when i right-click on jobs, there's no Run Now. i only get Refresh, New Job, and Object List Report.
able to configure everything and able to get a file in the specified output directory also. but the file size shows as 0kb and in statistis section of pgAgent job in pgAdmin III status shows as Successful.
Any suggestions?
Postgresql 8.3
I have installed successfully pgAgent and able to see the jobs--> Scheduler, Steps and created new job and scheduled for daily routine maintenance, but it is not working. i am trying to execute the sql commands in one of database pgAgent is runned as postgres user (i also tried with machine user no luck) any idea or suggestions job details shown as Last results Unknown Running at Not currently running
Thanx Leo for sharing such a wonderful tutorial for Setting up PgAgent and Doing Scheduled Backups...It's working perfectly for me..
Have a Great Day....
HI,
Is pgAgent really meant to run on "postgres" database?? If not, why is that when I select other database on which the step will run, it says, "Couldn't connect to the database!", but when i select the postgres database, it is running smoothly. If pgAgent can run in other database, can you teach me how can i do that? Thanks, Ged
if you are using windows, and the host name is localhost then be sure to use localhost in pgpass and not 127.0.0.1. or just use both.
127.0.0.1:2032:*:user:password localhost:2032:*:user:password |
QuicksearchCalendarCategoriesBlog AdministrationEntry's LinksShow tagged entries |
Tracked: Jul 15, 04:36