Skip to content

Commit

Permalink
Merge pull request #4872 from big-appled/cleanup-restic
Browse files Browse the repository at this point in the history
cleanup restic helper folder when done
  • Loading branch information
reasonerjt authored May 12, 2022
2 parents 9b52576 + e09c31e commit 89907bd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/4872-big-appled
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cleanup the .velero folder after restic done
31 changes: 31 additions & 0 deletions cmd/velero-restic-restore-helper/velero-restic-restore-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func main() {
case <-ticker.C:
if done() {
fmt.Println("All restic restores are done")
err := removeFolder()
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Done cleanup .velero folder")
}
return
}
}
Expand Down Expand Up @@ -75,3 +81,28 @@ func done() bool {

return true
}

// remove .velero folder
func removeFolder() error {
children, err := ioutil.ReadDir("/restores")
if err != nil {
return err
}

for _, child := range children {
if !child.IsDir() {
fmt.Printf("%s is not a directory, skipping.\n", child.Name())
continue
}

donePath := filepath.Join("/restores", child.Name(), ".velero")

err = os.RemoveAll(donePath)
if err != nil {
return err
}
fmt.Printf("Deleted %s", donePath)
}

return nil
}

0 comments on commit 89907bd

Please sign in to comment.