diff --git a/README.md b/README.md index 5c222a4..0633cf9 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ Options: The target path to the backup folder. (default "backup") -config.file string The path to your config file. (default "git-backup.yml") + -backup.fail-at-end + Fail at the end of backing up repositories, rather than right away. ``` ## Usage: Docker diff --git a/cmd/git-backup/main.go b/cmd/git-backup/main.go index ad0e5f8..532542c 100644 --- a/cmd/git-backup/main.go +++ b/cmd/git-backup/main.go @@ -11,6 +11,7 @@ import ( var configFilePath = flag.String("config.file", "git-backup.yml", "The path to your config file.") var targetPath = flag.String("backup.path", "backup", "The target path to the backup folder.") +var failAtEnd = flag.Bool("backup.fail-at-end", false, "Fail at the end of backing up repositories, rather than right away.") func main() { flag.Parse() @@ -22,6 +23,7 @@ func main() { os.Exit(111) } repoCount := 0 + errors := 0 backupStart := time.Now() for _, source := range sources { sourceName := source.GetName() @@ -45,13 +47,20 @@ func main() { } err = repo.CloneInto(targetPath) if err != nil { + errors++ log.Printf("Failed to clone: %s", err) - os.Exit(100) + if *failAtEnd == false { + os.Exit(100) + } } } repoCount++ } - log.Printf("Backed up %d repositories in %s", repoCount, time.Now().Sub(backupStart)) + log.Printf("Backed up %d repositories in %s, encountered %d errors", repoCount, time.Now().Sub(backupStart), errors) + + if errors > 0 { + os.Exit(100) + } } func loadConfig() gitbackup.Config {