3

I am currently working on a task which should take a backup of all AWS Codecommit repositories (around 60 repositories at the moment) and place them in an S3 bucket located in another AWS account.

I have googled it to find out the possibilities around this but found nothing that best suites my requirement.

1.) Considered using Code Pipeline:

We can configure AWS CodePipeline to use a branch in an AWS CodeCommit 
repository as the source stage for our code. In this way, when you make 
changes to your selected branch in CodePipeline, an archive of the 
repository at the tip of that branch will be delivered to your CodePipeline 
bucket.

But, I had to neglect this option as it could be applied only to a 
particular branch of a repository whereas I want a backup for 60 
repositories all at a time.

2.) Considered doing it using simple git command which clones the git repositories, placing the cloned stuff into a folder and sending them to S3 bucket in another account.

I had to neglect this because it complicates my process when a new git 
repository is created where I need to manually go to AWS account and get the 
url of that repo to clone.

So, I want to know if there is a good option to automatically backup Codecommit repositories in S3 located in a different AWS account. If something in any of the repos changes, it should automatically trigger that changed part and move it to S3.

prudhvi
  • 1,141
  • 6
  • 23
  • 46

2 Answers2

3

Here is how I would solve,

Steps:

  1. Create a CodeCommit Trigger under AWS CodeCommit Repository
  2. Listen on EC2 on Jenkins or a node express or any http app
  3. Get all latest commits from repo
  4. aws s3 sync . s3://bucketname

This is the fastest backup I can think of.

For Automatic Repository Creation, you can use list-repositories, http://docs.aws.amazon.com/cli/latest/reference/codecommit/list-repositories.html

if repo does not exist already, clone a new one or update the existing one.

You can also do git export to a single file and back that file with a versioning enabled on S3. This will increase backup time everytime it runs.

Codecommit backup

Kannaiyan
  • 12,554
  • 3
  • 44
  • 83
0

fully appreciate this thread is old, but i've just been tinkering with an EventBridge trigger for a commit on any repo, this event works for me, the target can then be set:

{
  "source": ["aws.codecommit"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["codecommit.amazonaws.com"],
    "eventName": ["GitPush"],
    "requestParameters": {
      "references": {
        "commit": [{
          "exists": true
        }]
      }
    }
  }
}

from there, iterate all repos to clone, then (in my case) git bundle and then move the bundle to the archive location...

Robert Swift
  • 333
  • 3
  • 9