@@ -136,7 +136,8 @@ def __init__(self, *args, **kwargs):
136136self .test_env ["LC_MESSAGES" ]= "C"
137137self .test_env ["LC_TIME" ]= "C"
138138
139- self .dir_path = os .path .dirname (os .path .realpath (__file__ ))
139+ self .helpers_path = os .path .dirname (os .path .realpath (__file__ ))
140+ self .dir_path = os .path .abspath (os .path .join (self .helpers_path ,os .pardir ))
140141try :
141142os .makedirs (os .path .join (self .dir_path ,"tmp_dirs" ))
142143except :
@@ -213,12 +214,16 @@ def get_md5_per_page_for_fork(self, file, size):
213214os .close (file )
214215return md5_per_page
215216
216- def get_ptrack_bits_per_page_for_fork (self ,file ,size ):
217+ def get_ptrack_bits_per_page_for_fork (self ,node ,file ,size ):
218+ if self .get_pgpro_edition (node )== 'enterprise' :
219+ header_size = 48
220+ else :
221+ header_size = 24
217222ptrack_bits_for_fork = []
218223byte_size = os .path .getsize (file + '_ptrack' )
219- byte_size_minus_header = byte_size - 24
224+ byte_size_minus_header = byte_size - header_size
220225file = os .open (file + '_ptrack' ,os .O_RDONLY )
221- os .lseek (file ,24 ,0 )
226+ os .lseek (file ,header_size ,0 )
222227lot_of_bytes = os .read (file ,byte_size_minus_header )
223228for byte in lot_of_bytes :
224229byte_inverted = bin (ord (byte ))[2 :].rjust (8 ,'0' )[::- 1 ]
@@ -295,7 +300,7 @@ def check_ptrack_clean(self, idx_dict, size):
295300
296301def run_pb (self ,command ,async = False ):
297302try :
298- #print [ self.probackup_path] + command
303+ self . cmd = [ ' ' . join ( map ( str ,[ self .probackup_path ]+ command ))]
299304if async is True :
300305return subprocess .Popen (
301306 [self .probackup_path ]+ command ,
@@ -304,23 +309,21 @@ def run_pb(self, command, async=False):
304309env = self .test_env
305310 )
306311else :
307- output = subprocess .check_output (
312+ self . output = subprocess .check_output (
308313 [self .probackup_path ]+ command ,
309314stderr = subprocess .STDOUT ,
310315env = self .test_env
311316 )
312317if command [0 ]== 'backup' :
313- if '-q' in command or '--quiet' in command :
314- return None
315- elif '-v' in command or '--verbose' in command :
316- return output
317- else :
318- # return backup ID
319- for line in output .splitlines ():
320- if 'INFO: Backup' and 'completed' in line :
321- return line .split ()[2 ]
318+ # return backup ID
319+ for line in self .output .splitlines ():
320+ if 'INFO: Backup' and 'completed' in line :
321+ return line .split ()[2 ]
322+ # backup_id = line.split()[2]
323+ # return {'cmd': cmd, 'output': output, 'backup_id': backup_id}
322324else :
323- return output
325+ return self .output
326+ # return {'cmd': cmd, 'output': output}
324327except subprocess .CalledProcessError as e :
325328raise ProbackupException (e .output ,e .cmd )
326329
@@ -481,25 +484,34 @@ def get_recovery_conf(self, node):
481484out_dict [key .strip ()]= value .strip (" '" ).replace ("'\n " ,"" )
482485return out_dict
483486
484- def set_archiving_conf (self ,node ,archive_dir ):
487+ def set_archiving_conf (self ,node ,archive_dir = False ,replica = False ):
488+ if not archive_dir :
489+ archive_dir = self .arcwal_dir (node )
490+
491+ if replica :
492+ archive_mode = 'always'
493+ node .append_conf ('postgresql.auto.conf' ,'hot_standby = on' )
494+ else :
495+ archive_mode = 'on'
496+
485497node .append_conf (
486498"postgresql.auto.conf" ,
487499"wal_level = archive"
488500 )
489501node .append_conf (
490502"postgresql.auto.conf" ,
491- "archive_mode =on"
503+ "archive_mode ={0}" . format ( archive_mode )
492504 )
493505if os .name == 'posix' :
494506node .append_conf (
495507"postgresql.auto.conf" ,
496508"archive_command = 'test ! -f {0}/%f && cp %p {0}/%f'" .format (archive_dir )
497509 )
498- elif os .name == 'nt' :
499- node .append_conf (
500- "postgresql.auto.conf" ,
501- "archive_command = 'copy %p {0}\\ %f'" .format (archive_dir )
502- )
510+ # elif os.name == 'nt':
511+ # node.append_conf(
512+ # "postgresql.auto.conf",
513+ # "archive_command = 'copy %p {0}\\%f'".format(archive_dir)
514+ # )
503515
504516def wrong_wal_clean (self ,node ,wal_size ):
505517wals_dir = os .path .join (self .backup_dir (node ),"wal" )
@@ -517,4 +529,9 @@ def guc_wal_block_size(self, node):
517529var = node .execute ("postgres" ,"select setting from pg_settings where name = 'wal_block_size'" )
518530return int (var [0 ][0 ])
519531
520- # def ptrack_node(self, ptrack_enable=False, wal_level='minimal', max_wal_senders='2', allow_replication=True)
532+ def get_pgpro_edition (self ,node ):
533+ if node .execute ("postgres" ,"select exists(select 1 from pg_proc where proname = 'pgpro_edition')" )[0 ][0 ]:
534+ var = node .execute ("postgres" ,"select pgpro_edition()" )
535+ return str (var [0 ][0 ])
536+ else :
537+ return False