@@ -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.
121133func (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.
198221func (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