2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-24 20:27:02 +01:00
"""
ID : issue - 5022
ISSUE : 5022
TITLE : Restore of shadowed database fails using - k ( " restore without shadow " ) switch
DESCRIPTION :
NOTES :
[ 23.11 .2021 ]
For unknow reason , on v4 .0 .0 .2496 the gstat - h does not report active shadow
and test thus fail .
JIRA : CORE - 4715
2022-02-02 15:46:19 +01:00
FBTEST : bugs . core_4715
2022-01-24 20:27:02 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2021-11-26 19:20:43 +01:00
from pathlib import Path
2022-01-24 20:27:02 +01:00
from firebird . qa import *
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
substitutions = [ ( ' ^((?!HASH_IN_SOURCE|RDB \\ $SHADOW_NUMBER|HASH_IN_RESTORED).)*$ ' , ' ' ) ,
( ' .*Shadow 1:.* ' , ' Shadow present ' ) ]
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
init_script = """
2021-04-26 20:07:00 +02:00
- - Confirmed on WI - T3 .0 .0 .31374 :
- - command " gbak -rep -k c4715.fbk -user SYSDBA -pas masterke localhost/3000:<path> \\ c4715-new.FDB "
- - produces :
- - gbak : ERROR : DELETE operation is not allowed for system table RDB $ FILES
- - gbak : Exiting before completion due to errors
recreate table test ( s varchar ( 30 ) ) ;
commit ;
2021-11-26 19:20:43 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
db = db_factory ( init = init_script )
2021-11-26 19:20:43 +01:00
2022-01-24 20:27:02 +01:00
act = python_act ( ' db ' , substitutions = substitutions )
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
HASH_IN_SOURCE 1499836372373901520
RDB $ SHADOW_NUMBER 1
2021-12-19 22:25:36 +01:00
Shadow present
2021-04-26 20:07:00 +02:00
HASH_IN_RESTORED 1499836372373901520
2021-11-26 19:20:43 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
bkp_file = temp_file ( ' core_4715-shadowed.fbk ' )
fdb_file = temp_file ( ' core_4715-restored.fdb ' )
2021-04-26 20:07:00 +02:00
2021-11-26 19:20:43 +01:00
@pytest.mark.version ( ' >=3.0 ' )
2022-01-24 20:27:02 +01:00
def test_1 ( act : Action , bkp_file : Path , fdb_file : Path , capsys ) :
act . isql ( switches = [ ' -q ' ] ,
input = f ''' create shadow 1 ' { act . db . db_path . with_suffix ( ' .shd ' ) } ' ; commit; insert into test select ' line # ' ||lpad(row_number()over(), 3, ' 0 ' ) from rdb$types rows 200; commit; set list on; select hash(list(s)) hash_in_source from test; select * from rdb$files; ''' )
print ( act . stdout )
act . reset ( )
act . isql ( switches = [ ] , input = ' show database; ' )
print ( act . stdout )
act . reset ( )
act . gbak ( switches = [ ' -b ' , act . db . dsn , str ( bkp_file ) ] )
act . reset ( )
act . gbak ( switches = [ ' -rep ' , ' -k ' , str ( bkp_file ) , str ( fdb_file ) ] )
act . reset ( )
act . isql ( switches = [ ' -q ' , str ( fdb_file ) ] , connect_db = False ,
2021-11-26 19:20:43 +01:00
input = ' set list on; select hash(list(s)) hash_in_restored from test; ' )
2022-01-24 20:27:02 +01:00
print ( act . stdout )
2021-11-26 19:20:43 +01:00
#
2022-01-24 20:27:02 +01:00
act . reset ( )
act . expected_stdout = expected_stdout
act . stdout = capsys . readouterr ( ) . out
assert act . clean_stdout == act . clean_expected_stdout