Skip to content
This repository was archived by the owner on Sep 20, 2022. It is now read-only.

Commit 4a736ea

Browse files
author
jsam
committed
fix() Cleanup strategy && Organisation 404 handler
1 parent 1bbeeef commit 4a736ea

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=0.1.3
1+
VERSION=0.1.4
22
BINARY_NAME=ghbackup
33

44
build:

config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
keep_last_backup_days: 7
22
organisations:
3-
- kawago
3+
- cawemo
44
- flowing
55
- bpmn-io
66
- camunda

main.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,42 @@ func (app *GithubBackup) uploadFileToS3(filePath string) {
117117
}
118118
}
119119

120+
func (app *GithubBackup) getS3Page(marker string) (*s3.ListObjectsOutput, error) {
121+
params := &s3.ListObjectsInput{
122+
Bucket: aws.String(app.config.S3Bucket),
123+
}
124+
125+
if len(marker) > 0 {
126+
params.Marker = aws.String(marker)
127+
}
128+
129+
return app.s3svc.ListObjects(params)
130+
}
131+
120132
// cleanup method will delete old backups. Backup which are older then specified in config will be deleted.
121133
func (app *GithubBackup) cleanup() {
122134
fmt.Println("[+] Starting CLEANUP.")
123135

124136
os.RemoveAll(strings.Split(TMP_REPO_PATH, "/")[0])
125137
os.RemoveAll(app.createdAt)
126138

127-
params := &s3.ListObjectsInput{
128-
Bucket: aws.String(app.config.S3Bucket),
139+
var objRefs []*s3.Object
140+
var marker string
141+
142+
for {
143+
resp, _ := app.getS3Page(marker)
144+
lastKey := resp.Contents[len(resp.Contents) - 1].Key
145+
objRefs = append(objRefs, resp.Contents...)
146+
147+
if *resp.IsTruncated == true {
148+
marker = *lastKey
149+
} else {
150+
break
151+
}
129152
}
130-
resp, _ := app.s3svc.ListObjects(params)
131153

132-
for _, key := range resp.Contents {
154+
fmt.Printf("[+] Found %d objects for cleanup.\n", len(objRefs))
155+
for _, key := range objRefs {
133156
fmt.Println(*key.Key)
134157
ts, _ := ParseTime(strings.Split(*key.Key, "/")[0])
135158
if int(time.Since(ts).Hours()) > app.config.KeepLastBackupDays * 24 {
@@ -197,7 +220,7 @@ func (app *GithubBackup) cloneRepository(repo *github.Repository, repoPath strin
197220
// downloadAll will fetch all repository endpoints for a given organisation and clone them to filesystem.
198221
func (app *GithubBackup) downloadAll(organisation string) {
199222
repos, err := app.getRepositories(organisation)
200-
checkErr(err)
223+
if err != nil { return }
201224

202225
for _, repo := range repos {
203226
path := fmt.Sprintf(TMP_REPO_PATH, app.createdAt, organisation, *repo.Name)

0 commit comments

Comments
 (0)