Module postgresql
source code
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>
|
|
|
_backupDatabase(targetDir,
compressMode,
user,
backupUser,
backupGroup,
database=None)
Backs up an individual PostgreSQL database, or all databases. |
source code
|
|
|
|
|
|
|
logger = <logging.Logger object>
|
|
POSTGRESQLDUMP_COMMAND = [ ' pg_dump ' ]
|
|
POSTGRESQLDUMPALL_COMMAND = [ ' pg_dumpall ' ]
|
|
__package__ = ' CedarBackup2.extend '
|
Executes the PostgreSQL backup action.
- Parameters:
configPath (String representing a path on disk.) - Path to configuration file on disk.
options (Options object.) - Program command-line options.
config (Config object.) - Program configuration.
- 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)
| source code
|
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)
| source code
|
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)
|
backupDatabase(user,
backupFile,
database=None)
| source code
|
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 (String representing PostgreSQL username.) - User to use for connecting to the database.
backupFile (Python file object as from open() or
file() .) - File use for writing backup.
database (String representing database name, or None for all
databases.) - Name of the database to be backed up.
- 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.
|