Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #98 from vshn/UnlockBeforeActions
Browse files Browse the repository at this point in the history
Remove stale locks before invoking other restic actions
  • Loading branch information
cimnine authored Jul 30, 2021
2 parents 83ef3d1 + a410868 commit e900322
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/wrestic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func run(resticCLI *restic.Restic, mainLogger logr.Logger) error {
return err
}

if err := resticCLI.Unlock(false); err != nil {
mainLogger.Error(err, "failed to remove stale locks from the repository, continuing anyway")
}

// This builds up the cache without any other side effect. So it won't block
// during any stdin backups or such.
if err := resticCLI.Snapshots(nil); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions restic/unlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package restic
import "github.com/vshn/wrestic/logging"

// Unlock will remove stale locks from the repository
// If the all flag is set to true, even non-stale locks are removed.
func (r *Restic) Unlock(all bool) error {
unlocklogger := r.logger.WithName("unlock")

unlocklogger.Info("unlocking repository", "all", all)

opts := CommandOptions{
Path: r.resticPath,
Args: r.globalFlags.ApplyToCommand("unlock"),
Path: r.resticPath,
Args: r.globalFlags.ApplyToCommand("unlock"),
StdOut: logging.NewErrorWriter(unlocklogger.WithName("restic")),
StdErr: logging.NewErrorWriter(unlocklogger.WithName("restic")),
}
Expand Down

0 comments on commit e900322

Please sign in to comment.