6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00
firebird-qa/tests/bugs/core_2216_test.py

88 lines
3.1 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-21 18:49:26 +01:00
"""
ID: issue-2644
ISSUE: 2644
TITLE: Nbackup as online dump
DESCRIPTION:
We create table and leave it empty, than we run "nbackup -b 0 <source_db> <nbk_level_0>".
After this add one row in the table in source DB.
Then we obtain database GUID of sourec DB and use it in following commands:
1. nbackup -b <GUID> <source_db> <addi_file>
2. nbackup -i -r <nbk_level_0> <addi_file>
Finally, we:
1. Check that inserted record actually does exist in <nbk_level_0>;
2. Run online validation of <nbk_level_0> - it sould NOT produce any errors.
JIRA: CORE-2216
FBTEST: bugs.core_2216
2022-01-21 18:49:26 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2021-11-15 19:01:46 +01:00
from pathlib import Path
2022-01-21 18:49:26 +01:00
from firebird.qa import *
2021-11-15 19:01:46 +01:00
from firebird.driver import SrvNBackupFlag
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
substitutions = [('BLOB_ID.*', ''),
2021-11-15 19:01:46 +01:00
('[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]', ''),
('Relation [0-9]{3,4}', 'Relation')]
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
init_script = """
2021-11-15 19:01:46 +01:00
create table test(id int, s varchar(10) unique using index test_s, t timestamp, b blob);
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
db = db_factory(init=init_script)
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
act = python_act('db', substitutions=substitutions)
2021-11-15 19:01:46 +01:00
nbak_file_base = temp_file('nbak-file.fdb')
nbak_file_add = temp_file('nbak-file.add')
2022-01-21 18:49:26 +01:00
expected_stdout_a = """
2021-04-26 20:07:00 +02:00
ID 1
S qwerty
T 2013-12-11 14:15:16.1780
foo-rio-bar
Records affected: 1
2021-11-15 19:01:46 +01:00
"""
2022-01-21 18:49:26 +01:00
expected_stdout_b = """
2021-04-26 20:07:00 +02:00
Validation started
Relation (TEST)
process pointer page 0 of 1
Index 1 (TEST_S)
Relation (TEST) is ok
Validation finished
2021-11-15 19:01:46 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2022-01-21 18:49:26 +01:00
def test_1(act: Action, nbak_file_base: Path, nbak_file_add: Path):
with act.connect_server() as srv, act.db.connect() as con:
2021-11-15 19:01:46 +01:00
# Backup base database
2022-01-21 18:49:26 +01:00
srv.database.nbackup(database=act.db.db_path, backup=nbak_file_base,
2021-11-15 19:01:46 +01:00
level=0)
c = con.cursor()
# get db GUID
c.execute('select rb.rdb$guid as db_guid from rdb$backup_history rb')
db_guid = c.fetchone()[0]
# Insert data
c.execute("insert into test(id,s,t,b) values(1, 'qwerty', '11.12.2013 14:15:16.178', 'foo-rio-bar')")
con.commit()
# Backup changes
2022-01-21 18:49:26 +01:00
srv.database.nbackup(database=act.db.db_path, backup=nbak_file_add,
2021-11-15 19:01:46 +01:00
guid=db_guid)
# Restore inplace
srv.database.nrestore(flags=SrvNBackupFlag.IN_PLACE, database=nbak_file_base,
2021-11-15 19:01:46 +01:00
backups=[str(nbak_file_add)])
# Check restored database
2022-01-21 18:49:26 +01:00
act.expected_stdout = expected_stdout_a
act.isql(switches=[str(nbak_file_base)],
2021-11-15 19:01:46 +01:00
connect_db=False,
input="set list on;set count on;set blob all;select id,s,t,b as blob_id from test;")
2022-01-21 18:49:26 +01:00
assert act.clean_stdout == act.clean_expected_stdout
2021-11-15 19:01:46 +01:00
# Validate restored database
srv.database.validate(database=nbak_file_base)
2022-01-21 18:49:26 +01:00
act.reset()
act.expected_stdout = expected_stdout_b
act.stdout = '\n'.join(srv.readlines())
assert act.clean_stdout == act.clean_expected_stdout