Example #1
0
def backup_pgsql(backup_directory, config, databases):
    """Backup databases in a Postgres instance

    :param backup_directory: directory to save pg_dump output to
    :param config: PgDumpPlugin config dictionary
    :raises: OSError, PgError on error
    """
    connection_params = pgauth2args(config)
    extra_options = pg_extra_options(config)

    pgenv = dict(os.environ)

    if config['pgauth']['password'] is not None:
        pgpass_file = generate_pgpassfile(backup_directory,
                                          config['pgauth']['password'])
        if 'PGPASSFILE' in pgenv:
            LOG.warn("Overriding PGPASSFILE in environment with %s because "
                     "a password is specified.",
                      pgpass_file)
        pgenv['PGPASSFILE'] = pgpass_file

    backup_globals(backup_directory, config, connection_params, env=pgenv)

    ext_map = {
        'custom' : '.dump',
        'plain' : '.sql',
        'tar' : '.tar',
    }


    backups = []
    for dbname in databases:
        format = config['pgdump']['format']

        dump_name, _ = encode_safe(dbname)
        if dump_name != dbname:
            LOG.warn("Encoded database %s as filename %s", dbname, dump_name)

        filename = os.path.join(backup_directory, dump_name + ext_map[format])

        zopts = config['compression']
        stream = open_stream(filename, 'w',
                             method=zopts['method'],
                             level=zopts['level'],
                             extra_args=zopts['options'])

        backups.append((dbname, stream.name))

        run_pgdump(dbname=dbname,
                   output_stream=stream,
                   connection_params=connection_params + extra_options,
                   format=format,
                   env=pgenv)

        stream.close()

    generate_manifest(backups, backup_directory)
Example #2
0
def backup_pgsql(backup_directory, config, databases):
    """Backup databases in a Postgres instance

    :param backup_directory: directory to save pg_dump output to
    :param config: PgDumpPlugin config dictionary
    :raises: OSError, PgError on error
    """
    connection_params = pgauth2args(config)
    extra_options = pg_extra_options(config)

    pgenv = dict(os.environ)

    if config['pgauth']['password'] is not None:
        pgpass_file = generate_pgpassfile(backup_directory,
                                          config['pgauth']['password'])
        if 'PGPASSFILE' in pgenv:
            LOG.warn(
                "Overriding PGPASSFILE in environment with %s because "
                "a password is specified.", pgpass_file)
        pgenv['PGPASSFILE'] = pgpass_file

    backup_globals(backup_directory, config, connection_params, env=pgenv)

    ext_map = {
        'custom': '.dump',
        'plain': '.sql',
        'tar': '.tar',
    }

    backups = []
    for dbname in databases:
        format = config['pgdump']['format']

        dump_name, _ = encode_safe(dbname)
        if dump_name != dbname:
            LOG.warn("Encoded database %s as filename %s", dbname, dump_name)

        filename = os.path.join(backup_directory, dump_name + ext_map[format])

        zopts = config['compression']
        stream = open_stream(filename,
                             'w',
                             method=zopts['method'],
                             level=zopts['level'],
                             extra_args=zopts['options'])

        backups.append((dbname, stream.name))

        run_pgdump(dbname=dbname,
                   output_stream=stream,
                   connection_params=connection_params + extra_options,
                   format=format,
                   env=pgenv)

        stream.close()

    generate_manifest(backups, backup_directory)
Example #3
0
def backup_pgsql(backup_directory, config, databases):
    """Backup databases in a Postgres instance

    :param backup_directory: directory to save pg_dump output to
    :param config: PgDumpPlugin config dictionary
    :raises: OSError, PgError on error
    """
    connection_params = pgauth2args(config)
    extra_options = pg_extra_options(config)

    pgenv = dict(os.environ)

    if config["pgauth"]["password"] is not None:
        pgpass_file = generate_pgpassfile(backup_directory,
                                          config["pgauth"]["password"])
        if "PGPASSFILE" in pgenv:
            LOG.warning(
                "Overriding PGPASSFILE in environment with %s because "
                "a password is specified.",
                pgpass_file,
            )
        pgenv["PGPASSFILE"] = pgpass_file

    backup_globals(backup_directory, config, connection_params, env=pgenv)

    ext_map = {"custom": ".dump", "plain": ".sql", "tar": ".tar"}

    backups = []
    for dbname in databases:
        out_format = config["pgdump"]["format"]

        dump_name = encode_safe(dbname)
        if dump_name != dbname:
            LOG.warning("Encoded database %s as filename %s", dbname,
                        dump_name)

        filename = os.path.join(backup_directory,
                                dump_name + ext_map[out_format])

        stream = open_stream(filename, "w", **config["compression"])
        backups.append((dbname, stream.name))

        run_pgdump(
            dbname=dbname,
            output_stream=stream,
            connection_params=connection_params + extra_options,
            out_format=out_format,
            env=pgenv,
        )

        stream.close()

    generate_manifest(backups, backup_directory)
Example #4
0
def backup_pgsql(backup_directory, config, databases):
    """Backup databases in a Postgres instance

    :param backup_directory: directory to save pg_dump output to
    :param config: PgDumpPlugin config dictionary
    :raises: OSError, PgError on error
    """
    connection_params = pgauth2args(config)
    extra_options = pg_extra_options(config)

    pgenv = dict(os.environ)

    if config["pgauth"]["password"] is not None:
        pgpass_file = generate_pgpassfile(backup_directory, config["pgauth"]["password"])
        if "PGPASSFILE" in pgenv:
            LOG.warning(
                "Overriding PGPASSFILE in environment with %s because " "a password is specified.",
                pgpass_file,
            )
        pgenv["PGPASSFILE"] = pgpass_file

    backup_globals(backup_directory, config, connection_params, env=pgenv)

    ext_map = {"custom": ".dump", "plain": ".sql", "tar": ".tar"}

    backups = []
    for dbname in databases:
        out_format = config["pgdump"]["format"]

        dump_name = encode_safe(dbname)
        if dump_name != dbname:
            LOG.warning("Encoded database %s as filename %s", dbname, dump_name)

        filename = os.path.join(backup_directory, dump_name + ext_map[out_format])

        stream = open_stream(filename, "w", **config["compression"])
        backups.append((dbname, stream.name))

        run_pgdump(
            dbname=dbname,
            output_stream=stream,
            connection_params=connection_params + extra_options,
            out_format=out_format,
            env=pgenv,
        )

        stream.close()

    generate_manifest(backups, backup_directory)