@@ -149,12 +149,7 @@ func (w *ResticWrapper) backupFromStdin(options BackupOptions) ([]byte, error) {
149
149
klog .Infoln ("Backing up stdin data" )
150
150
151
151
// first add StdinPipeCommands, then add restic command
152
- var commands []Command
153
- if len (options .StdinPipeCommands ) != 0 {
154
- for i := range options .StdinPipeCommands {
155
- commands = append (commands , options .StdinPipeCommands [i ])
156
- }
157
- }
152
+ commands := options .StdinPipeCommands
158
153
159
154
args := []interface {}{"backup" , "--stdin" , "--quiet" , "--json" }
160
155
if options .StdinFileName != "" {
@@ -177,6 +172,19 @@ func (w *ResticWrapper) backupFromStdin(options BackupOptions) ([]byte, error) {
177
172
func (w * ResticWrapper ) cleanup (retentionPolicy v1alpha1.RetentionPolicy , host string ) ([]byte , error ) {
178
173
klog .Infoln ("Cleaning old snapshots according to retention policy" )
179
174
175
+ out , err := w .tryCleanup (retentionPolicy , host )
176
+ if err == nil || ! strings .Contains (err .Error (), "unlock" ) {
177
+ return out , err
178
+ }
179
+ // repo is locked, so unlock first
180
+ klog .Warningln ("repo found locked, so unlocking before pruning, err:" , err .Error ())
181
+ if o2 , e2 := w .unlock (); e2 != nil {
182
+ return o2 , e2
183
+ }
184
+ return w .tryCleanup (retentionPolicy , host )
185
+ }
186
+
187
+ func (w * ResticWrapper ) tryCleanup (retentionPolicy v1alpha1.RetentionPolicy , host string ) ([]byte , error ) {
180
188
args := []interface {}{"forget" , "--quiet" , "--json" }
181
189
182
190
if host != "" {
@@ -304,11 +312,7 @@ func (w *ResticWrapper) dump(dumpOptions DumpOptions) ([]byte, error) {
304
312
commands := []Command {
305
313
{Name : ResticCMD , Args : args },
306
314
}
307
- if len (dumpOptions .StdoutPipeCommands ) != 0 {
308
- for i := range dumpOptions .StdoutPipeCommands {
309
- commands = append (commands , dumpOptions .StdoutPipeCommands [i ])
310
- }
311
- }
315
+ commands = append (commands , dumpOptions .StdoutPipeCommands ... )
312
316
return w .run (commands ... )
313
317
}
314
318
0 commit comments