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. |
|
_backupDatabase (targetDir,
compressMode,
user,
backupUser,
backupGroup,
database)
Backs up an individual PostgreSQL database, or all databases. |
|
_getOutputFile (targetDir,
database,
compressMode)
Opens the output file used for saving the PostgreSQL dump. |
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.
|
_backupDatabase(targetDir,
compressMode,
user,
backupUser,
backupGroup,
database=None)
Backs up an individual PostgreSQL database, or all databases.
This internal method wraps the public method and adds some
functionality, like figuring out a filename, etc.
-
- Parameters:
targetDir -
Directory into which backups should be written.
compressMode -
Compress mode to be used for backed-up files.
user -
User to use for connecting to the database.
backupUser -
User to own resulting file.
backupGroup -
Group to own resulting file.
database -
Name of database, or None for all databases.
- Returns:
-
Name of the generated backup file.
- Raises:
ValueError -
If some value is missing or invalid.
IOError -
If there is a problem executing the PostgreSQL dump.
|
_getOutputFile(targetDir,
database,
compressMode)
Opens the output file used for saving the PostgreSQL dump.
The filename is either "postgresqldump.txt"
or "postgresqldump-<database>.txt" . The
".gz" or ".bz2" extension
is added if compress is True .
-
- Parameters:
targetDir -
Target directory to write file in.
database -
Name of the database (if any)
compressMode -
Compress mode to be used for backed-up files.
- Returns:
-
Tuple of (Output file object, filename)
|
logger
-
- Type:
-
Logger
- Value:
<logging.Logger instance at 0x403fcd8c>
|
|
POSTGRESQLDUMP_COMMAND
-
- Type:
-
list
- Value:
|
POSTGRESQLDUMPALL_COMMAND
-
- Type:
-
list
- Value:
|