Skip to content

Commit

Permalink
Initial release - v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerfcsantos committed Feb 28, 2021
1 parent 79880ff commit a8e91b5
Show file tree
Hide file tree
Showing 32 changed files with 3,248 additions and 32 deletions.
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# IDEs
**/.idea/**

# Distributables
dist/

# Binaries for programs and plugins
*.exe
*.exe~
Expand All @@ -11,5 +17,6 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
# brestore binaries on root folder
./brestore.exe
./brestore
29 changes: 1 addition & 28 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down Expand Up @@ -172,30 +172,3 @@
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.PHONY: all build clean
all: build

build:
./build.sh

clean:
rm -rf dist
144 changes: 142 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,142 @@
# bucket-restore
Point in time restores for buckets in Amazon Web Services (AWS) S3 and Google Cloud Platform (GCP) Storage.
# `brestore` - Bucket Restore for AWS and GCP

[![Go Report Card](https://goreportcard.com/badge/github.com/viltgroup/bucket-restore)](https://goreportcard.com/report/github.com/viltgroup/bucket-restore)
[![GoDoc](https://godoc.org/github.com/viltgroup/bucket-restore?status.svg)](https://godoc.org/github.com/viltgroup/bucket-restore)

A program that does point in time restores for buckets in Amazon Web Services (AWS) S3 and Google Cloud Platform (GCP) Storage.

## Features

* Rollback objects in a bucket to a previous state.
* Rollback all objects in a bucket or only specific ones.
* Dry runs - preview changes before committing to a rollback
* Check versions/generations of objects in a bucket
* Works with multiple objects at the same time for fast restores
* Doesn't delete object history - it's always possible to undo a rollback

## Download

`brestore` is distributed as a single binary that can be downloaded in the [releases section](https://github.com/viltgroup/bucket-restore/releases) of this repository.

* [Brestore releases download](https://github.com/viltgroup/bucket-restore/releases)

## Install using Go

If you have Go 1.16+ installed, you can install `brestore` on your machine with `go get`:

go get github.com/viltgroup/bucket-restore/cmd/brestore

This will install `brestore` on your machine. The location where Go installs packages depends on how your environment is set up, but this folder is typically in `$HOME/go/bin`.

## Examples

### Rollback actions

* Rollback all objects in the AWS S3 bucket 'mybucket' to a specific point in time:

`brestore rollback --bucket s3://mybucket --time "February 21, 2021, 23:00:00 (UTC+01:00)"`

* The same as the previous command, but for gcp storage:

`brestore rollback --bucket gs://mybucket --time "February 21, 2021, 23:00:00 (UTC+01:00)"`

* Rollback a specific object or all objects under a path inside the bucket:

`brestore rollback --bucket gs://mybucket/path/to/dir_or_file --time "February 21, 2021, 23:00:00 (UTC+01:00)"`

* To perform a dry run, add the flag `--dry-run-explain` or `--dry-run` to the rollback command:

`brestore versions --bucket gs://mybucket/ --time "February 21, 2021, 23:00:00 (UTC+01:00)" --dry-run-explain`

### Check object versions/generations:

* Show all versions for all objects in a bucket:

`brestore versions --bucket s3://mybucket`

* Show all versions for a specific object or objects in a path:

`brestore versions --bucket s3://mybucket/path/to/dir_or_file`

## Usage

`brestore <command> [flags]`

**Available commands**

* `help` - Help about any command
* `rollback` - Rollback objects in a bucket to a specific point in time. Aliases: `restore`.
* `version` - Shows the current version of brestore
* `versions` - Shows the versions/generations of objects. Aliases: `gens`, `history`, `generations`.

**Global Flags**

* `-p, --aws-profile string` - name of the AWS profile to use to perform requests.

* `-b, --bucket string` - the URI to the bucket to which rollback/listing actions shouldbe applied.
* `-k, --gcp-key-file string` - path to a JSON key file of a GCP Service Account
* `-h, --help` - help for brestore
* `-t, --time string` - the point in time where to restore to.

**Rollback flags**

* `-d, --dry-run` - summary of the changes that will be made if the rollback is run.
* `-e, --dry-run-explain` - same as '--dry-run' but shows additional information for each object about the current state and the state of the object in the point in time given to the --time flag.
* `-h, --help` - help for rollback
* `-c, --max-concurrency int` - maximum number of rollback actions that can run concurrently.
* `-q, --quiet` - show less output.

## Authentication

To perform actions, `brestore` needs make authenticated requests to AWS/GCP. This explains how authentication credentials can be provided to `brestore`.

### Amazon Web Services (AWS)

`brestore` will try to fetch the credential information from the [AWS shared credentials file](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/create-shared-credentials-file.html).
Typically, this file is located at `~/.aws/credentials`. You can put credentials in this file either manually or with [AWS Cli](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html).

This file can include different credential profiles, including a default one. `brestore` will try to use the default profile if no profile is given. You can tell `brestore` to use another profile inside the shared credentials file by adding `--aws-profile <profile_name>` to your command. The profile used must have permissions to read bucket information and to create/delete/list objects.

### Google Cloud Platform (GCP)

`brestore` will try to fetch credentials from a JSON File containing a key of a Service Account. The key file can be specified by passing `--gcp-key-file <path_to_key_file>` to `brestore` or by setting the environment variable `GOOGLE_APPLICATION_CREDENTIALS` with the path to the key file. If both the flag and the envrionemnt variables are set, the path set in the flag will take precedence and will be used. The Service Account to which the key belongs must have permissions to read bucket information and to create/delete/list objects.

## Time formats

The `--time` flag allows a point in time to be specified in several formats. Below are examples of the date 'January 02, 2006, 15:04:05 (UTC-07:00)' in all formats accepted by `brestore`:

<details>
<summary>Supported time formats</summary>

**Formats similar to the ones in the AWS UI:**

January 02, 2006, 15:04:05 (UTC-07:00)
Jan 02, 2006, 15:04:05 (UTC-07:00)
January 02, 2006, 15:04:05 (-07:00)
Jan 02, 2006, 15:04:05 (-07:00)

**Formats similar to the ones in the GCP UI:**

Jan 02, 2006, 03:04:05 PM -07:00
Jan 02, 2006, 03:04:05 PM MST
January 02, 2006, 03:04:05 PM -07:00
January 02, 2006, 03:04:05 PM MST

**Other allowed formats:**

02-01-2006 15:04:05 -07:00
02-01-2006 15:04:05 MST
02-01-2006 03:04:05 PM -07:00
02-01-2006 03:04:05 PM MST
2006-01-02 15:04:05 -07:00
2006-01-02 03:04:05 PM MST
2006-01-02 03:04:05 PM -07:00
2006-01-02 03:04:05 PM MST
Mon, 02 Jan 2006 15:04:05 MST
2006-01-02T15:04:05Z07:00

</details>

## License

Apache License 2.0, see [LICENSE](https://github.com/viltgroup/bucket-restore/blob/master/LICENSE).
30 changes: 30 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

LIST=(`go tool dist list`)

for item in "${LIST[@]}"; do
items=(`echo "${item}" | tr "/" "\n"`);
tags=$(git tag --sort=committerdate);
target_tag=${tags[0]};
OS=${items[0]};
ARCH=${items[1]};
FOLDER="./dist/brestore-${target_tag}.${OS}-${ARCH}"
if GOOS="${OS}" GOARCH="${ARCH}" go build -o "$FOLDER/" ./cmd/brestore 2> /dev/null; then
echo "Generated $OS/$ARCH";
cp README.md LICENSE "$FOLDER";
cd dist
BASENAME="brestore-${target_tag}.${OS}-${ARCH}"
if [ $OS = "windows" ]; then
zip -m --quiet -r "${BASENAME}.zip" "${BASENAME}"
else
tar --remove-files -czf "${BASENAME}.tar.gz" "${BASENAME}"
fi
cd ..
else
echo "Skipping $OS/$ARCH";
fi
done

cd dist

sha256sum *.gz *.zip > sha256sums.txt
1 change: 1 addition & 0 deletions cmd/brestore/appcmds/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
38 changes: 38 additions & 0 deletions cmd/brestore/appcmds/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2021 VILT Group
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package appcmds

import (
"fmt"
"os"
)

func saveErrorsToFile(filename string, errors []error) error {
f, err := os.Create(filename)
defer f.Close()

if err != nil {
return err
}

for _, e := range errors {
_, err = fmt.Fprintf(f, "%v\n", e)
if err != nil {
return err
}
}

return nil
}
Loading

0 comments on commit a8e91b5

Please sign in to comment.