Example #1
0
def test_backup_and_restore_sqlite():
    logging.basicConfig(level=logging.DEBUG)
    backup_dir = tempfile.mkdtemp()
    try:
        dbfile = os.path.join(backup_dir, "test.db")
        dbsetup.setup(modules=[backup_test_db])
        dbsetup.init('sqlite:///' + dbfile)
        dbsetup.create()

        s = session()
        s.add(backup_test_db.TestTable(id="1", foo="bar"))
        transaction.commit()

        rows = s.query(backup_test_db.TestTable).filter(backup_test_db.TestTable.foo == "bar").all()
        assert rows

        backup.dump_database(s, backup_dir)

        now = datetime.datetime.now()
        dump_file = os.path.join(backup_dir, "test.db.dump.{:%Y%m%d-%H%M}.gz".format(now))

        assert os.path.isfile(dump_file)

        dbsetup.destroy()
        dbsetup.create()
        rows = s.query(backup_test_db.TestTable).all()
        assert not rows

        backup.load_database(s, dbsetup.Base.metadata, dump_file)

        rows = s.query(backup_test_db.TestTable).filter(backup_test_db.TestTable.foo == "bar").all()
        assert rows

    finally:
        shutil.rmtree(backup_dir)
Example #2
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    dbsetup.setup(dbsetup.modules_from_config(settings, 'commondb.'))
    dbsetup.init_from_config(settings, 'sqlalchemy.')
    with transaction.manager:
        dbsetup.create()
Example #3
0
def common_db_configure(settings, use_transaction=True):
    """Configure common db using the given pyramid settings.

    This will use 'commondb.' and 'sqlalchemy.' in the configuration.

    :returns: None

    """
    dbsetup.setup(dbsetup.modules_from_config(settings, 'commondb.'))
    dbsetup.init_from_config(
        settings, 'sqlalchemy.', use_transaction=use_transaction
    )
Example #4
0
def common_db_configure(settings, use_transaction=True):
    """Configure common db using the given pyramid settings.

    This will use 'commondb.' and 'sqlalchemy.' in the configuration.

    :returns: None

    """
    if 'sqlalchemy' not in settings:
        get_log().warn(
            "common_db_configure: sqlalchemy not present disabling.")

    else:
        dbsetup.setup(dbsetup.modules_from_config(settings, 'commondb.'))
        dbsetup.init_from_config(settings,
                                 'sqlalchemy.',
                                 use_transaction=use_transaction)
Example #5
0
def common_db_configure(settings, use_transaction=True):
    """Configure common db using the given pyramid settings.

    This will use 'commondb.' and 'sqlalchemy.' in the configuration.

    :returns: None

    """
    if 'sqlalchemy' not in settings:
        get_log().warn(
            "common_db_configure: sqlalchemy not present disabling."
        )

    else:
        dbsetup.setup(dbsetup.modules_from_config(settings, 'commondb.'))
        dbsetup.init_from_config(
            settings, 'sqlalchemy.', use_transaction=use_transaction
        )
Example #6
0
def test_backup_and_restore_sqlite():
    logging.basicConfig(level=logging.DEBUG)
    backup_dir = tempfile.mkdtemp()
    try:
        dbfile = os.path.join(backup_dir, "test.db")
        dbsetup.setup(modules=[backup_test_db])
        dbsetup.init('sqlite:///' + dbfile)
        dbsetup.create()

        s = session()
        s.add(backup_test_db.TestTable(id="1", foo="bar"))
        transaction.commit()

        rows = s.query(backup_test_db.TestTable).filter(
            backup_test_db.TestTable.foo == "bar").all()
        assert rows

        backup.dump_database(s, backup_dir)

        now = datetime.datetime.now()
        dump_file = os.path.join(backup_dir,
                                 "test.db.dump.{:%Y%m%d-%H%M}.gz".format(now))

        assert os.path.isfile(dump_file)

        dbsetup.destroy()
        dbsetup.create()
        rows = s.query(backup_test_db.TestTable).all()
        assert not rows

        backup.load_database(s, dbsetup.Base.metadata, dump_file)

        rows = s.query(backup_test_db.TestTable).filter(
            backup_test_db.TestTable.foo == "bar").all()
        assert rows

    finally:
        shutil.rmtree(backup_dir)