Git Product home page Git Product logo

s3-backup's Introduction

S3 Backup

GitHub Marketplace

A GitHub action to mirror a repository to S3 compatible object storage.

Usage

This example will mirror your repository to an S3 bucket called repo-backup-bucket and at the optional key /at/some/path. Objects at the target will be overwritten, and extraneous objects will be removed. This default usage keeps your S3 backup in sync with GitHub.

    - name: S3 Backup
      uses: peter-evans/s3-backup@v1
      env:
        ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
        SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
        MIRROR_TARGET: repo-backup-bucket/at/some/path
      with:
        args: --overwrite --remove

S3 Backup uses the mirror command of MinIO Client. Additional arguments may be passed to the action via the args parameter.

Secrets and environment variables

The following variables may be passed to the action as secrets or environment variables. MIRROR_TARGET, for example, if considered sensitive should be passed as a secret.

  • ACCESS_KEY_ID (required) - The storage service access key id.
  • SECRET_ACCESS_KEY (required) - The storage service secret access key.
  • MIRROR_TARGET (required) - The target bucket, and optionally, the key within the bucket.
  • AWS_SESSION_TOKEN - When using temporary credentials (Amazon S3)
  • AWS_REGION (required with AWS_SESSION_TOKEN) - the region where the s3 bucket is located for Amazon S3. Mandatory when using SESSION_TOKEN.
  • MIRROR_SOURCE - The source defaults to the repository root. If required a path relative to the root can be set.
  • STORAGE_SERVICE_URL - The URL to the object storage service. Defaults to https://s3.amazonaws.com for Amazon S3.
  • STORAGE_SERVICE_ALIAS - Defaults to s3. See MinIO Client for other options such as S3 compatible minio, and gcs for Google Cloud Storage.

IAM user policy

The IAM user associated with the ACCESS_KEY_ID and SECRET_ACCESS_KEY should have s3:* policy access.

If required you can create a policy to restrict access to specific resources. The following policy grants the user access to the bucket my-restricted-bucket and its contents.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowBucketStat",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": "arn:aws:s3:::my-restricted-bucket"
        },
        {
            "Sid": "AllowThisBucketOnly",
            "Effect": "Allow",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::my-restricted-bucket/*",
                "arn:aws:s3:::my-restricted-bucket"
            ]
        }
    ]
}

Complete workflow example

The workflow below filters push events for the master branch before mirroring to S3.

name: Mirror repo to S3
on:
  push:
    branches:
      - master
jobs:
  s3Backup:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: S3 Backup
        uses: peter-evans/s3-backup@v1
        env:
          ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
          MIRROR_TARGET: ${{ secrets.MIRROR_TARGET }}
          SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
        with:
          args: --overwrite --remove

License

MIT

s3-backup's People

Contributors

dependabot[bot] avatar leos avatar peter-evans avatar shinitiandrei avatar vse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

s3-backup's Issues

Including other repository metadata?

I'm looking into repository backup solutions. While I like the idea of using a GH action, it appears that s3-backup only saves the git repository data and none of the GitHub-specific metadata (eg: issues, PRs, wiki, etc.). Is this correct?

Also, I'm assuming adding support for this would be non-trivial?

Thanks!

All S3 buckets deleted when passing MIRROR_TARGET=""

I tried out this action at work today, and accidentally passed an empty string to MIRROR_TARGET. Later I noticed that an important S3 bucket had been deleted. I went through the CloudTrail logs to find the knucklehead that did this, and saw that the bucket was deleted when I ran this action with the empty string.

I tried to reproduce this issue on my personal AWS account by creating a dummy bucket called aaaaa-first-bucket so that it would be shown at the top of the list, and then ran the same action to see if the bucket would be deleted.

But something worse happened. ALL OF MY S3 BUCKETS WERE DELETED!!!

Thankfully I didn't have anything too important on my personal account, but this could be catastrophic for other developers.

image

image

This is the configuration I used:

jobs:
  backup:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v2

      - name: S3 Backup
        uses: peter-evans/s3-backup@v1
        env:
          ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          MIRROR_TARGET: ""
        with:
          args: --overwrite --remove

Does this include all branches / history?

Sorry if this is a stupid question, but does this backup all of my branches / commit history?

I have it setup like the example, to run on push of the master branch.

Encryption

Great action! ๐Ÿ…

Have you thought about adding encryption support? That way S3/AWS wouldn't be able to read the source code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.