@@ -1018,46 +1018,76 @@ def set_archiving(
10181018 self , backup_dir , instance , node , replica = False ,
10191019 overwrite = False , compress = False , old_binary = False ):
10201020
1021+ # parse postgresql.auto.conf
1022+ options = {}
10211023 if replica :
1022- archive_mode = 'always'
1023- node . append_conf ( 'postgresql.auto.conf' , 'hot_standby = on')
1024+ options [ ' archive_mode' ] = 'always'
1025+ options [ 'hot_standby' ] = ' on'
10241026 else :
1025- archive_mode = 'on'
1027+ options [ ' archive_mode' ] = 'on'
10261028
1027- node .append_conf (
1028- 'postgresql.auto.conf' ,
1029- 'archive_mode = {0}' .format (archive_mode )
1030- )
10311029 if os .name == 'posix' :
1032- archive_command = '"{0}" archive-push -B {1} --instance={2} ' .format (
1030+ options [ ' archive_command' ] = '"{0}" archive-push -B {1} --instance={2} ' .format (
10331031 self .probackup_path , backup_dir , instance )
10341032
10351033 elif os .name == 'nt' :
1036- archive_command = '"{0}" archive-push -B {1} --instance={2} ' .format (
1034+ options [ ' archive_command' ] = '"{0}" archive-push -B {1} --instance={2} ' .format (
10371035 self .probackup_path .replace ("\\ " ,"\\ \\ " ),
1038- backup_dir .replace ("\\ " ,"\\ \\ " ),
1039- instance )
1036+ backup_dir .replace ("\\ " ,"\\ \\ " ), instance )
10401037
10411038 # don`t forget to kill old_binary after remote ssh release
10421039 if self .remote and not old_binary :
1043- archive_command = archive_command + '--remote-proto=ssh --remote-host=localhost '
1040+ options ['archive_command' ] += '--remote-proto=ssh '
1041+ options ['archive_command' ] += '--remote-host=localhost '
10441042
10451043 if self .archive_compress or compress :
1046- archive_command = archive_command + '--compress '
1044+ options [ ' archive_command' ] += '--compress '
10471045
10481046 if overwrite :
1049- archive_command = archive_command + '--overwrite '
1047+ options [ ' archive_command' ] += '--overwrite '
10501048
10511049 if os .name == 'posix' :
1052- archive_command = archive_command + '--wal-file-path=%p --wal-file-name=%f'
1050+ options [ ' archive_command' ] += '--wal-file-path=%p --wal-file-name=%f'
10531051
10541052 elif os .name == 'nt' :
1055- archive_command = archive_command + '--wal-file-path="%p" --wal-file-name="%f"'
1053+ options [ ' archive_command' ] += '--wal-file-path="%p" --wal-file-name="%f"'
10561054
1057- node .append_conf (
1058- 'postgresql.auto.conf' ,
1059- "archive_command = '{0}'" .format (
1060- archive_command ))
1055+ self .set_auto_conf (node , options )
1056+
1057+ def set_auto_conf (self , node , options ):
1058+
1059+ # parse postgresql.auto.conf
1060+ path = os .path .join (node .data_dir , 'postgresql.auto.conf' )
1061+
1062+ with open (path , 'r' ) as f :
1063+ raw_content = f .read ()
1064+
1065+ current_options = {}
1066+ for line in raw_content .splitlines ():
1067+
1068+ # ignore comments
1069+ if line .startswith ('#' ):
1070+ continue
1071+
1072+ name , var = line .partition ('=' )[::2 ]
1073+ name = name .strip ()
1074+ var = var .strip ()
1075+ var = var .strip ('"' )
1076+ var = var .strip ("'" )
1077+ current_options [name ] = var
1078+
1079+ for option in options :
1080+ current_options [option ] = options [option ]
1081+
1082+ auto_conf = ''
1083+ for option in current_options :
1084+ auto_conf += "{0} = '{1}'\n " .format (
1085+ option , current_options [option ])
1086+
1087+ with open (path , 'wt' ) as f :
1088+ f .write (auto_conf )
1089+ f .flush ()
1090+ f .close ()
10611091
10621092 def set_replica (
10631093 self , master , replica ,
0 commit comments