@@ -136,7 +136,11 @@ func (r *Local) Backup(info BackupInfo) error {
136136 }
137137 defer outfile .Close ()
138138 global .LOG .Infof ("start to pg_dump | gzip > %s.gzip" , info .TargetDir + "/" + info .FileName )
139- cmd := exec .Command (
139+
140+ ctx , cancel := context .WithTimeout (context .Background (), time .Duration (info .Timeout * uint (time .Second )))
141+ defer cancel ()
142+ cmd := exec .CommandContext (
143+ ctx ,
140144 "docker" , "exec" , "-i" , r .ContainerName ,
141145 "sh" , "-c" ,
142146 fmt .Sprintf ("PGPASSWORD=%s pg_dump -F c -U %s -d %s" , r .Password , r .Username , info .Name ),
@@ -159,8 +163,11 @@ func (r *Local) Backup(info BackupInfo) error {
159163func (r * Local ) Recover (info RecoverInfo ) error {
160164 fi , _ := os .Open (info .SourceFile )
161165 defer fi .Close ()
162- cmd := exec .Command ("docker" , "exec" , r .ContainerName , "sh" , "-c" ,
163- fmt .Sprintf ("PGPASSWORD=%s pg_dump -F c -U %s -d %s" , r .Password , r .Username , info .Name ),
166+
167+ ctx , cancel := context .WithTimeout (context .Background (), time .Duration (info .Timeout * uint (time .Second )))
168+ defer cancel ()
169+ cmd := exec .CommandContext (ctx , "docker" , "exec" , "-i" , r .ContainerName , "sh" , "-c" ,
170+ fmt .Sprintf ("PGPASSWORD=%s pg_restore -F c -U %s -d %s" , r .Password , r .Username , info .Name ),
164171 )
165172 if strings .HasSuffix (info .SourceFile , ".gz" ) {
166173 gzipFile , err := os .Open (info .SourceFile )
0 commit comments