Package CedarBackup2 :: Package extend :: Module postgresql
[show private | hide private]
[frames | no frames]

Module CedarBackup2.extend.postgresql

Provides an extension to back up PostgreSQL databases.

This is a Cedar Backup extension used to back up PostgreSQL databases via the Cedar Backup command line. It requires a new configurations section <postgresql> and is intended to be run either immediately before or immediately after the standard collect action. Aside from its own configuration, it requires the options and collect configuration sections in the standard Cedar Backup configuration file.

The backup is done via the pg_dump or pg_dumpall commands included with the PostgreSQL product. Output can be compressed using gzip or bzip2. Administrators can configure the extension either to back up all databases or to back up only specific databases. The extension assumes that the current user has passwordless access to the database since there is no easy way to pass a password to the pg_dump client. This can be accomplished using appropriate voodoo in the pg_hda.conf file.

Note that this code always produces a full backup. There is currently no facility for making incremental backups.

You should always make /etc/cback.conf unreadble to non-root users once you place postgresql configuration into it, since postgresql configuration will contain information about available PostgreSQL databases and usernames.

Use of this extension may expose usernames in the process listing (via ps) when the backup is running if the username is specified in the configuration.
Authors:
Kenneth J. Pronovici <pronovic@ieee.org>, Antoine Beaupre <anarcat@koumbit.org>
Classes
LocalConfig Class representing this extension's configuration document.
PostgresqlConfig Class representing PostgreSQL configuration.

Function Summary
  backupDatabase(user, backupFile, database)
Backs up an individual PostgreSQL database, or all databases.
  executeAction(configPath, options, config)
Executes the PostgreSQL backup action.

Variable Summary
Logger logger = <logging.Logger instance at 0x403fcd8c>
list POSTGRESQLDUMP_COMMAND = ['pg_dump']
list POSTGRESQLDUMPALL_COMMAND = ['pg_dumpall']

Function Details

backupDatabase(user, backupFile, database=None)

Backs up an individual PostgreSQL database, or all databases.

This function backs up either a named local PostgreSQL database or all local PostgreSQL databases, using the passed in user for connectivity. This is always a full backup. There is no facility for incremental backups.

The backup data will be written into the passed-in back file. Normally, this would be an object as returned from open(), but it is possible to use something like a GzipFile to write compressed output. The caller is responsible for closing the passed-in backup file.
Parameters:
user - User to use for connecting to the database.
           (type=String representing PostgreSQL username.)
backupFile - File use for writing backup.
           (type=Python file object as from open() or file().)
database - Name of the database to be backed up.
           (type=String representing database name, or None for all databases.)
Raises:
ValueError - If some value is missing or invalid.
IOError - If there is a problem executing the PostgreSQL dump.

Note: Typically, you would use the root user to back up all databases.

executeAction(configPath, options, config)

Executes the PostgreSQL backup action.
Parameters:
configPath - Path to configuration file on disk.
           (type=String representing a path on disk.)
options - Program command-line options.
           (type=Options object.)
config - Program configuration.
           (type=Config object.)
Raises:
ValueError - Under many generic error conditions
IOError - If a backup could not be written for some reason.

Variable Details

logger

Type:
Logger
Value:
<logging.Logger instance at 0x403fcd8c>                                

POSTGRESQLDUMP_COMMAND

Type:
list
Value:
['pg_dump']                                                            

POSTGRESQLDUMPALL_COMMAND

Type:
list
Value:
['pg_dumpall']                                                         

Generated by Epydoc 2.1 on Thu Mar 29 20:58:31 2007 http://epydoc.sf.net