6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_2208_test.py

151 lines
5.3 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-2636
ISSUE: 2636
TITLE: New gbak option to ignore specific tables data during the backup
DESCRIPTION:
We create four tables with ascii and one with non-ascii (cyrillic) names.
Each table has one row.
Then we check that one may to:
1) skip BACKUP data of some tables
2) skip RESTORE data for same tables.
All cases are checked by call 'fbsvcmgr ... bkp_skip_data <pattern>',
where <pattern> string matches several tables (i.e. we use SIMILAR_TO ability).
JIRA: CORE-2208
"""
2021-04-26 20:07:00 +02:00
import pytest
2021-11-15 19:01:46 +01:00
from io import BytesIO
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 SrvRestoreFlag
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
init_script = """
2021-04-26 20:07:00 +02:00
recreate table test_01(id char(1));
recreate table test_02(id char(1));
recreate table test_0a(id char(1));
recreate table test_0b(id char(1));
2021-11-15 19:01:46 +01:00
2021-04-26 20:07:00 +02:00
recreate table "опечатка"(id char(1));
commit;
insert into test_01(id) values('1');
insert into test_02(id) values('2');
insert into test_0a(id) values('3');
insert into test_0b(id) values('4');
insert into "опечатка"(id) values('ы');
commit;
-- similar to '(о|а)(п|ч)(е|и)(п|ч)(а|я)(т|д)(к|г)(а|о)';
recreate view v_check as
2021-11-15 19:01:46 +01:00
select 'test_01' as msg, t.id
2021-04-26 20:07:00 +02:00
from rdb$database left join test_01 t on 1=1
2021-11-15 19:01:46 +01:00
union all
select 'test_02' as msg, t.id
2021-04-26 20:07:00 +02:00
from rdb$database left join test_02 t on 1=1
union all
2021-11-15 19:01:46 +01:00
select 'test_0a' as msg, t.id
2021-04-26 20:07:00 +02:00
from rdb$database left join test_0a t on 1=1
2021-11-15 19:01:46 +01:00
union all
select 'test_0b' as msg, t.id
2021-04-26 20:07:00 +02:00
from rdb$database left join test_0b t on 1=1
union all
select 'опечатка' as msg, t.id
from rdb$database left join "опечатка" t on 1=1
2021-11-15 19:01:46 +01:00
;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
db = db_factory(charset='UTF8', init=init_script)
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
act = python_act('db')
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
expected_stdout_a = """
2021-11-15 19:01:46 +01:00
MSG test_01
ID 1
MSG test_02
ID 2
MSG test_0a
ID <null>
MSG test_0b
ID <null>
MSG опечатка
ID ы
Records affected: 5
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
expected_stdout_b = """
2021-11-15 19:01:46 +01:00
MSG test_01
ID <null>
MSG test_02
ID <null>
MSG test_0a
ID 3
MSG test_0b
ID 4
MSG опечатка
ID ы
Records affected: 5
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
expected_stdout_c = """
2021-11-15 19:01:46 +01:00
MSG test_01
ID 1
MSG test_02
ID 2
MSG test_0a
ID 3
MSG test_0b
ID 4
MSG опечатка
ID <null>
Records affected: 5
"""
2021-04-26 20:07:00 +02:00
2021-11-15 19:01:46 +01:00
# We need additional test database for restore
2022-01-21 18:49:26 +01:00
tmp_db = temp_file('extra-test.fdb')
2021-11-15 19:01:46 +01:00
@pytest.mark.version('>=3.0')
2022-01-21 18:49:26 +01:00
def test_1(act: Action, tmp_db: Path):
2021-11-15 19:01:46 +01:00
check_script = 'set list on; set count on; select * from v_check;'
2022-01-21 18:49:26 +01:00
if tmp_db.is_file():
tmp_db.unlink()
with act.connect_server() as srv:
2021-11-15 19:01:46 +01:00
backup = BytesIO()
# Run-1: try to skip BACKUP of data for tables 'test_0a' and 'test_0b'.
2022-01-21 18:49:26 +01:00
srv.database.local_backup(database=act.db.db_path, backup_stream=backup,
2021-11-15 19:01:46 +01:00
skip_data='test_0[[:alpha:]]')
backup.seek(0)
2022-01-21 18:49:26 +01:00
srv.database.local_restore(backup_stream=backup, database=tmp_db)
2021-11-15 19:01:46 +01:00
# check
2022-01-21 18:49:26 +01:00
act.expected_stdout = expected_stdout_a
act.isql(switches=[str(tmp_db)], input=check_script, connect_db=False)
assert act.clean_stdout == act.clean_expected_stdout
2021-11-15 19:01:46 +01:00
# Run-2: try to skip RESTORE of data for tables 'test_01' and 'test_02'.
2022-01-21 18:49:26 +01:00
if tmp_db.is_file():
tmp_db.unlink()
2021-11-15 19:01:46 +01:00
backup.close()
backup = BytesIO()
2022-01-21 18:49:26 +01:00
srv.database.local_backup(database=act.db.db_path, backup_stream=backup)
2021-11-15 19:01:46 +01:00
backup.seek(0)
2022-01-21 18:49:26 +01:00
srv.database.local_restore(backup_stream=backup, database=tmp_db,
2021-11-15 19:01:46 +01:00
skip_data='test_0[[:digit:]]')
# check
2022-01-21 18:49:26 +01:00
act.reset()
act.expected_stdout = expected_stdout_b
act.isql(switches=[str(tmp_db)], input=check_script, connect_db=False)
assert act.clean_stdout == act.clean_expected_stdout
2021-11-15 19:01:46 +01:00
# Run-3: try to skip BACKUP of data for table "опечатка".
srv.encoding = 'utf8'
2022-01-21 18:49:26 +01:00
if tmp_db.is_file():
tmp_db.unlink()
2021-11-15 19:01:46 +01:00
backup.close()
backup = BytesIO()
2022-01-21 18:49:26 +01:00
srv.database.local_backup(database=act.db.db_path, backup_stream=backup,
2021-11-15 19:01:46 +01:00
skip_data='(о|а)(п|ч)(е|и)(п|ч)(а|я)(т|д)(к|г)(о|а)')
backup.seek(0)
2022-01-21 18:49:26 +01:00
srv.database.local_restore(backup_stream=backup, database=tmp_db)
2021-11-15 19:01:46 +01:00
# check
2022-01-21 18:49:26 +01:00
act.reset()
act.expected_stdout = expected_stdout_c
act.isql(switches=[str(tmp_db)], input=check_script, connect_db=False)