Beispiel #1
0
def load(
    state, host,
    remote_filename, database=None,
    # Details for speaking to PostgreSQL via `psql` CLI
    postgresql_user=None, postgresql_password=None,
    postgresql_host=None, postgresql_port=None,
):
    '''
    Load ``.sql`` file into a database.

    + database: name of the database to import into
    + remote_filename: the filename to read from
    + postgresql_*: global module arguments, see above

    Example:

    .. code:: python

        postgresql.load(
            {'Import the pyinfra_stuff dump into pyinfra_stuff_copy'},
            '/tmp/pyinfra_stuff.dump',
            database='pyinfra_stuff_copy',
            sudo_user='******',
        )

    '''

    yield StringCommand(make_psql_command(
        database=database,
        user=postgresql_user,
        password=postgresql_password,
        host=postgresql_host,
        port=postgresql_port,
    ), '<', remote_filename)
Beispiel #2
0
def dump(
    state, host,
    remote_filename, database=None,
    # Details for speaking to PostgreSQL via `psql` CLI
    postgresql_user=None, postgresql_password=None,
    postgresql_host=None, postgresql_port=None,
):
    '''
    Dump a PostgreSQL database into a ``.sql`` file. Requires ``pg_dump``.

    + database: name of the database to dump
    + remote_filename: name of the file to dump the SQL to
    + postgresql_*: global module arguments, see above

    Example:

    .. code:: python

        postgresql.dump(
            {'Dump the pyinfra_stuff database'},
            '/tmp/pyinfra_stuff.dump',
            database='pyinfra_stuff',
            sudo_user='******',
        )

    '''

    yield StringCommand(make_psql_command(
        executable='pg_dump',
        database=database,
        user=postgresql_user,
        password=postgresql_password,
        host=postgresql_host,
        port=postgresql_port,
    ), '>', remote_filename)
Beispiel #3
0
def load(
    state,
    host,
    remote_filename,
    database=None,
    # Details for speaking to PostgreSQL via `psql` CLI
    postgresql_user=None,
    postgresql_password=None,
    postgresql_host=None,
    postgresql_port=None,
):
    '''
    Load ``.sql`` file into a database.

    + database: name of the database to import into
    + remote_filename: the filename to read from
    + postgresql_*: global module arguments, see above
    '''

    yield '{0} < {1}'.format(
        make_psql_command(
            database=database,
            user=postgresql_user,
            password=postgresql_password,
            host=postgresql_host,
            port=postgresql_port,
        ), remote_filename)
Beispiel #4
0
def dump(
    state,
    host,
    remote_filename,
    database=None,
    # Details for speaking to PostgreSQL via `psql` CLI
    postgresql_user=None,
    postgresql_password=None,
    postgresql_host=None,
    postgresql_port=None,
):
    '''
    Dump a PostgreSQL database into a ``.sql`` file. Requires ``mysqldump``.

    + database: name of the database to dump
    + remote_filename: name of the file to dump the SQL to
    + postgresql_*: global module arguments, see above
    '''

    yield '{0} > {1}'.format(
        make_psql_command(
            executable='pg_dump',
            database=database,
            user=postgresql_user,
            password=postgresql_password,
            host=postgresql_host,
            port=postgresql_port,
        ), remote_filename)
Beispiel #5
0
def dump(
    dest,
    database=None,
    # Details for speaking to PostgreSQL via `psql` CLI
    psql_user=None,
    psql_password=None,
    psql_host=None,
    psql_port=None,
):
    """
    Dump a PostgreSQL database into a ``.sql`` file. Requires ``pg_dump``.

    + dest: name of the file to dump the SQL to
    + database: name of the database to dump
    + psql_*: global module arguments, see above

    **Example:**

    .. code:: python

        postgresql.dump(
            name="Dump the pyinfra_stuff database",
            dest="/tmp/pyinfra_stuff.dump",
            database="pyinfra_stuff",
            sudo_user="******",
        )

    """

    yield StringCommand(
        make_psql_command(
            executable="pg_dump",
            database=database,
            user=psql_user,
            password=psql_password,
            host=psql_host,
            port=psql_port,
        ),
        ">",
        dest,
    )
Beispiel #6
0
def load(
    src,
    database=None,
    # Details for speaking to PostgreSQL via `psql` CLI
    psql_user=None,
    psql_password=None,
    psql_host=None,
    psql_port=None,
):
    """
    Load ``.sql`` file into a database.

    + src: the filename to read from
    + database: name of the database to import into
    + psql_*: global module arguments, see above

    **Example:**

    .. code:: python

        postgresql.load(
            name="Import the pyinfra_stuff dump into pyinfra_stuff_copy",
            src="/tmp/pyinfra_stuff.dump",
            database="pyinfra_stuff_copy",
            sudo_user="******",
        )

    """

    yield StringCommand(
        make_psql_command(
            database=database,
            user=psql_user,
            password=psql_password,
            host=psql_host,
            port=psql_port,
        ),
        "<",
        src,
    )