@@ -17,47 +17,50 @@ def read_configuration():
17
17
parser .add_argument ('--recovery-target-time' ,
18
18
help = 'the timestamp up to which recovery will proceed (including time zone)' ,
19
19
dest = 'recovery_target_time_string' )
20
- parser .add_argument ('--dry-run' , action = 'store_true' , help = 'find a matching backup and build the wal-e '
21
- 'command to fetch that backup without running it' )
20
+ parser .add_argument ('--config-include-path' ,
21
+ help = 'pgbackrest configuration directory' )
22
22
args = parser .parse_args ()
23
23
24
- options = namedtuple ('Options' , 'name datadir recovery_target_time dry_run ' )
24
+ options = namedtuple ('Options' , 'name datadir recovery_target_time config_include_path ' )
25
25
if args .recovery_target_time_string :
26
26
recovery_target_time = parse (args .recovery_target_time_string )
27
27
if recovery_target_time .tzinfo is None :
28
28
raise Exception ("recovery target time must contain a timezone" )
29
29
else :
30
30
recovery_target_time = None
31
31
32
- return options (args .scope , args .datadir , recovery_target_time , args .dry_run )
32
+ return options (args .scope , args .datadir , recovery_target_time , args .config_include_path )
33
33
34
34
def run_clone_from_pgbackrest (options ):
35
35
env = os .environ .copy ()
36
36
37
37
pg_path_argument = "--pg1-path={0}" .format (options .datadir )
38
38
39
+ pgbackrest_command = ['/usr/bin/pgbackrest' , 'restore' , '--stanza=db' , pg_path_argument ]
40
+
41
+ if options .config_include_path :
42
+ pgbackrest_command .extend (['--config-include-path=' + options .config_include_path ])
43
+
39
44
if options .recovery_target_time :
40
45
target_time_argument = "--target={0}" .format (options .recovery_target_time )
41
- pgbackrest_command = ['/usr/bin/pgbackrest' , '--stanza=db' , '--type=time' , target_time_argument , 'restore' , pg_path_argument ]
42
- else :
43
- pgbackrest_command = ['/usr/bin/pgbackrest' , '--stanza=db' , 'restore' , pg_path_argument ]
46
+ pgbackrest_command .extend (['--type=time' , target_time_argument ])
44
47
45
48
logger .info ("cloning cluster %s using %s" , options .name , ' ' .join (pgbackrest_command ))
46
49
47
- if not options . dry_run :
48
- ret = subprocess . call ( pgbackrest_command , env = env )
49
- if ret != 0 :
50
- raise Exception ( "pgbackrest restore exited with exit code {0}" . format ( ret ))
50
+ ret = subprocess . call ( pgbackrest_command , env = env )
51
+ if ret != 0 :
52
+ logger . error ( "pgbackrest restore exited with exit code {0}" . format ( ret ))
53
+ return ret
51
54
52
55
return 0
53
56
54
57
def main ():
55
- options = read_configuration ()
56
58
try :
59
+ options = read_configuration ()
57
60
run_clone_from_pgbackrest (options )
58
61
except Exception :
59
62
logger .exception ("Clone with pgbackrest failed" )
60
63
return 1
61
64
62
65
if __name__ == '__main__' :
63
- sys .exit (main ())
66
+ sys .exit (main ())
0 commit comments