Re: vacuum and backup - Mailing list pgsql-general

From Brent R. Matzelle
Subject Re: vacuum and backup
Date
Msg-id 20010227181931.9803.qmail@web312.mail.yahoo.com
Whole thread Raw
In response to vacuum and backup  (Colleen Williams <colleen@digital-arts.co.uk>)
List pgsql-general
> 3) Has anyone written some shell scripts to do vacuum and
> backup?
> I will have to write some but am not conversant with shell
> scripts and
> would greatly appreciate any help.

You would probably be better off writing your scripts in a
system language such as Python or Perl.  Here is an excerpt from
a basic Python backup program I wrote (uses pg_dump &
postgresql-python) that does just that.

#!/usr/bin/python
import os, time
from pg import DB

# Backup database with the current date attached
def pg_backup():
    now = time.localtime(time.time())
    today = time.strftime("%m-%d-%Y", now)
    os.system("pg_dump test > test-%s.sql" % today)
    print "Backup completed"

# Run vacuum on database
def pg_clean():
    cxn = DB('test')
    cxn.query("VACUUME VERBOSE ANALYZE")
    print "Database optimized & space recovered"

### This is the main program ###
if __name__ == "__main__":
    pg_backup()
    pg_clean()

Brent

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/

pgsql-general by date:

Previous
From: "Brent R. Matzelle"
Date:
Subject: Re: PHP4.0.4pl1 and PostgreSQL 7.1beta4
Next
From: Doug McNaught
Date:
Subject: Re: vacuum and backup