【问题标题】:Trying to have a backup of Codecommit repos in S3 bucket of another AWS account尝试在另一个 AWS 账户的 S3 存储桶中备份 Codecommit 存储库
【发布时间】:2017-09-19 09:04:45
【问题描述】:

我目前正在处理一项任务,该任务应备份所有 AWS Codecommit 存储库(目前大约 60 个存储库)并将它们放在另一个 AWS 账户中的 S3 存储桶中。

我已经用谷歌搜索了它以找出与此相关的可能性,但没有找到最适合我的要求。

1.) 考虑使用代码管道:

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.) 考虑使用克隆 git 的简单 git 命令执行此操作 存储库,将克隆的东西放入一个文件夹并将它们发送到 S3 存储在另一个帐户中

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.

所以,我想知道是否有一个好的选项可以自动备份位于不同 AWS 账户的 S3 中的 Codecommit 存储库。如果任何 repos 中的某些内容发生更改,它应该会自动触发更改的部分并将其移动到 S3。

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-lambda aws-codecommit


    【解决方案1】:

    这是我的解决方法,

    步骤:

    1. 在 AWS CodeCommit 存储库下创建 CodeCommit 触发器
    2. 收听在 Jenkins 上的 EC2 或 node express 或任何 http 应用程序
    3. 从 repo 中获取 所有最新提交
    4. aws s3 同步。 s3://bucketname

    这是我能想到的最快的备份。

    对于自动存储库创建,您可以使用 list-repositories, http://docs.aws.amazon.com/cli/latest/reference/codecommit/list-repositories.html

    如果 repo 不存在,克隆一个新的或更新现有的。

    您还可以将 git 导出到单个文件并在 S3 上启用版本控制的情况下返回该文件。这将增加每次运行时的备份时间。

    【讨论】:

    • 我认为您也可以尝试使用指向 AWS Lambda 函数的触发器,该函数可以针对每个存储库进行配置。
    • 我还没有看到你可以为所有回购做通用触发器。它仅适用于每个存储库。
    【解决方案2】:

    完全感谢这个线程是旧的,但我刚刚修改了一个 EventBridge 触发器以在任何 repo 上提交,这个事件对我有用,然后可以设置目标:

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

    从那里,迭代所有 repos 以克隆,然后(在我的情况下)git bundle,然后将包移动到存档位置...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-28
      • 2017-07-21
      • 2019-01-15
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-03
      相关资源
      最近更新 更多