Skip to content

Commit 886bee7

Browse files
committed
Add docs
1 parent 834e954 commit 886bee7

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# git-backup
2+
3+
A cli to pull all your GitHub repositories for backup purposes.
4+
5+
## Download
6+
7+
The latest version can be downloaded from the [releases page](https://github.com/ChappIO/git-backup/releases).
8+
9+
## Configuration
10+
11+
Example Configuration:
12+
```yaml
13+
# The github section contains backup jobs for
14+
# GitHub and GitHub Enterprise
15+
github:
16+
# (optional) The job name. This is used to
17+
# create a subfolder in the backup folder.
18+
# (default: GitHub)
19+
- job_name: github.com
20+
# (required) The GitHub personal access
21+
# token. Create one with the scopes:
22+
# "read:org, repo"
23+
# https://github.com/settings/tokens/new?scopes=repo,read:org
24+
access_token: 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
25+
```
26+
27+
## Usage
28+
29+
```asciidoc
30+
Usage: git-backup
31+
32+
Options:
33+
-backup.path string
34+
The target path to the backup folder. (default "backup")
35+
-config.file string
36+
The path to your config file. (default "git-backup.yml")
37+
```

cmd/git-backup/main.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package main
22

33
import (
4+
"flag"
45
gitbackup "git-backup"
56
"log"
67
"os"
78
"path/filepath"
89
)
910

11+
var configFilePath = flag.String("config.file", "git-backup.yml", "The path to your config file.")
12+
var targetPath = flag.String("backup.path", "backup", "The target path to the backup folder.")
13+
1014
func main() {
15+
flag.Parse()
16+
1117
config := loadConfig()
1218
for _, source := range config.GetSources() {
1319
sourceName := source.GetName()
@@ -23,7 +29,7 @@ func main() {
2329
}
2430
for _, repo := range repos {
2531
log.Printf("Discovered %s", repo.FullName)
26-
targetPath := filepath.Join("backup", sourceName, repo.FullName)
32+
targetPath := filepath.Join(*targetPath, sourceName, repo.FullName)
2733
err := os.MkdirAll(targetPath, os.ModePerm)
2834
if err != nil {
2935
log.Printf("Failed to create directory: %s", err)
@@ -34,14 +40,13 @@ func main() {
3440
log.Printf("Failed to clone: %s", err)
3541
os.Exit(100)
3642
}
37-
3843
}
3944
}
4045
}
4146

4247
func loadConfig() gitbackup.Config {
4348
// try config file in working directory
44-
config, err := gitbackup.LoadFile("./git-backup.yml")
49+
config, err := gitbackup.LoadFile(*configFilePath)
4550
if os.IsNotExist(err) {
4651
log.Println("No config file found. Exiting...")
4752
os.Exit(1)
@@ -50,4 +55,4 @@ func loadConfig() gitbackup.Config {
5055
os.Exit(1)
5156
}
5257
return config
53-
}
58+
}

0 commit comments

Comments
 (0)