Skip to content

Commit 18d0eed

Browse files
authored
Added a backup.fail-at-end option (#4)
Using this option it will continue with all repositories even when encountering an error. It will only exit with an error after processing all repositories.
1 parent ef29485 commit 18d0eed

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Options:
7676
The target path to the backup folder. (default "backup")
7777
-config.file string
7878
The path to your config file. (default "git-backup.yml")
79+
-backup.fail-at-end
80+
Fail at the end of backing up repositories, rather than right away.
7981
```
8082

8183
## Usage: Docker

cmd/git-backup/main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
var configFilePath = flag.String("config.file", "git-backup.yml", "The path to your config file.")
1313
var targetPath = flag.String("backup.path", "backup", "The target path to the backup folder.")
14+
var failAtEnd = flag.Bool("backup.fail-at-end", false, "Fail at the end of backing up repositories, rather than right away.")
1415

1516
func main() {
1617
flag.Parse()
@@ -22,6 +23,7 @@ func main() {
2223
os.Exit(111)
2324
}
2425
repoCount := 0
26+
errors := 0
2527
backupStart := time.Now()
2628
for _, source := range sources {
2729
sourceName := source.GetName()
@@ -45,13 +47,20 @@ func main() {
4547
}
4648
err = repo.CloneInto(targetPath)
4749
if err != nil {
50+
errors++
4851
log.Printf("Failed to clone: %s", err)
49-
os.Exit(100)
52+
if *failAtEnd == false {
53+
os.Exit(100)
54+
}
5055
}
5156
}
5257
repoCount++
5358
}
54-
log.Printf("Backed up %d repositories in %s", repoCount, time.Now().Sub(backupStart))
59+
log.Printf("Backed up %d repositories in %s, encountered %d errors", repoCount, time.Now().Sub(backupStart), errors)
60+
61+
if errors > 0 {
62+
os.Exit(100)
63+
}
5564
}
5665

5766
func loadConfig() gitbackup.Config {

0 commit comments

Comments
 (0)