@@ -136,7 +136,8 @@ def __init__(self, *args, **kwargs):
136
136
self .test_env ["LC_MESSAGES" ]= "C"
137
137
self .test_env ["LC_TIME" ]= "C"
138
138
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 ))
140
141
try :
141
142
os .makedirs (os .path .join (self .dir_path ,"tmp_dirs" ))
142
143
except :
@@ -213,12 +214,16 @@ def get_md5_per_page_for_fork(self, file, size):
213
214
os .close (file )
214
215
return md5_per_page
215
216
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
217
222
ptrack_bits_for_fork = []
218
223
byte_size = os .path .getsize (file + '_ptrack' )
219
- byte_size_minus_header = byte_size - 24
224
+ byte_size_minus_header = byte_size - header_size
220
225
file = os .open (file + '_ptrack' ,os .O_RDONLY )
221
- os .lseek (file ,24 ,0 )
226
+ os .lseek (file ,header_size ,0 )
222
227
lot_of_bytes = os .read (file ,byte_size_minus_header )
223
228
for byte in lot_of_bytes :
224
229
byte_inverted = bin (ord (byte ))[2 :].rjust (8 ,'0' )[::- 1 ]
@@ -295,7 +300,7 @@ def check_ptrack_clean(self, idx_dict, size):
295
300
296
301
def run_pb (self ,command ,async = False ):
297
302
try :
298
- #print [ self.probackup_path] + command
303
+ self . cmd = [ ' ' . join ( map ( str ,[ self .probackup_path ]+ command ))]
299
304
if async is True :
300
305
return subprocess .Popen (
301
306
[self .probackup_path ]+ command ,
@@ -304,23 +309,21 @@ def run_pb(self, command, async=False):
304
309
env = self .test_env
305
310
)
306
311
else :
307
- output = subprocess .check_output (
312
+ self . output = subprocess .check_output (
308
313
[self .probackup_path ]+ command ,
309
314
stderr = subprocess .STDOUT ,
310
315
env = self .test_env
311
316
)
312
317
if 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}
322
324
else :
323
- return output
325
+ return self .output
326
+ # return {'cmd': cmd, 'output': output}
324
327
except subprocess .CalledProcessError as e :
325
328
raise ProbackupException (e .output ,e .cmd )
326
329
@@ -481,25 +484,34 @@ def get_recovery_conf(self, node):
481
484
out_dict [key .strip ()]= value .strip (" '" ).replace ("'\n " ,"" )
482
485
return out_dict
483
486
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
+
485
497
node .append_conf (
486
498
"postgresql.auto.conf" ,
487
499
"wal_level = archive"
488
500
)
489
501
node .append_conf (
490
502
"postgresql.auto.conf" ,
491
- "archive_mode =on"
503
+ "archive_mode ={0}" . format ( archive_mode )
492
504
)
493
505
if os .name == 'posix' :
494
506
node .append_conf (
495
507
"postgresql.auto.conf" ,
496
508
"archive_command = 'test ! -f {0}/%f && cp %p {0}/%f'" .format (archive_dir )
497
509
)
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
+ # )
503
515
504
516
def wrong_wal_clean (self ,node ,wal_size ):
505
517
wals_dir = os .path .join (self .backup_dir (node ),"wal" )
@@ -517,4 +529,9 @@ def guc_wal_block_size(self, node):
517
529
var = node .execute ("postgres" ,"select setting from pg_settings where name = 'wal_block_size'" )
518
530
return int (var [0 ][0 ])
519
531
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