Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mittwald/brudi into mittw…
Browse files Browse the repository at this point in the history
…ald#19/AdditionalResticFunctionality
  • Loading branch information
YannikBramkamp committed Jan 11, 2021
2 parents 0fd3910 + 8ae78ab commit e7d3b4e
Show file tree
Hide file tree
Showing 56 changed files with 3,487 additions and 257 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Go

on: [push, pull_request]

jobs:

build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --snapshot --skip-publish -f build/ci/.goreleaser.yml

test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Install restic
run: |
wget https://github.com/restic/restic/releases/download/v0.11.0/restic_0.11.0_linux_amd64.bz2
bzip2 -d restic_0.11.0_linux_amd64.bz2
sudo mv restic_0.11.0_linux_amd64 /usr/local/bin/restic
sudo chown root:root /usr/local/bin/restic
sudo chmod +x /usr/local/bin/restic
- name: install redis-cli
run: sudo apt-get install redis-tools

- name: Test
run: go test -v ./...
env:
RESTIC_PASSWORD: mongorepo
46 changes: 0 additions & 46 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ COMMIT_HASH = $(shell git rev-parse --verify HEAD)
CURDIR = $(shell pwd)
GOLANGCI_LINT_VER = v1.33.0

.PHONY: build
.PHONY: build test

all: dep test lint build

Expand Down
190 changes: 182 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ When it comes to backup-creation there are several solutions to use.
In general everybody's doing some sort of `dump` or `tar` and backing up the results incremental with [`restic`](https://github.com/restic/restic) or similar programs.

This is why `brudi` was born. `brudi` supports several backup-methods and is configurable by a simple `yaml` file.
The advantage of `brudi` is, that you can create a backup of a source of your choice and save it with `restic` aftwards in one step.
The advantage of `brudi` is, that you can create a backup of a source of your choice and save it with `restic` afterwards in one step.
Under the hood, `brudi` uses the given binaries like `mysqldump`, `mongodump`, `pg_dump`, `tar` or `restic`.

Using `brudi` will save you from finding yourself writing bash-scripts to create your backups.

Besides creating backups, `brudi` can also be used to restore your data from backup in an emergency.

## Table of contents

- [Usage](#usage)
Expand All @@ -29,8 +31,16 @@ Using `brudi` will save you from finding yourself writing bash-scripts to create
- [Rebuild-Index](#rebuild-index)
- [Tags](#tags)
- [Sensitive data: Environment variables](#sensitive-data--environment-variables)
- [Restoring from backup](#restoring-from-backup)
- [TarRestore](#tarrestore)
- [MongoRestore](#mongorestore)
- [MySQLRestore](#mysqlrestore)
- [PgRestore](#pgrestore)
- [Restore using pg_restore](#restore-using-pg_restore)
- [Restore using psql](#restore-using-psql)
- [Featurestate](#featurestate)
- [Source backup methods](#source-backup-methods)
- [Restore backup methods](#restore-backup-methods)
- [Incremental backup of the source backups](#incremental-backup-of-the-source-backups)

## Usage
Expand All @@ -56,13 +66,18 @@ Usage:
brudi [command]

Available Commands:
help Help about any command
mongodump Creates a mongodump of your desired server
mysqldump Creates a mysqldump of your desired server
pgdump Creates a pg_dump of your desired postgresql-server
redisdump Creates an rdb dump of your desired server
tar Creates a tar archive of your desired paths
version Print the version number of brudi
help Help about any command
mongodump Creates a mongodump of your desired server
mongorestore Restores a server from a mongodump
mysqldump Creates a mysqldump of your desired server
mysqlrestore Restores a database from an sqldump
pgdump Creates a pg_dump of your desired postgresql-server
pgrestore Restores a database from a pgdump using pg_restore
psql Restores a database from a plain-text pgdump using psql
redisdump Creates an rdb dump of your desired server
tar Creates a tar archive of your desired
tarrestore Restores files from a tar archive
version Print the version number of brudi

Flags:
--cleanup cleanup backup files afterwards
Expand Down Expand Up @@ -370,6 +385,155 @@ export MONGODUMP_OPTIONS_FLAGS_PASSWORD="mongodbroot"
As soon as a variable for a key exists in your environment, the value of this environment-variable is used in favour of your `.yaml`-config.
#### Restoring from backup
#### TarRestore
```yaml
tarrestore:
options:
flags:
extract: true
gzip: true
file: /tmp/test.tar.gz
target: "/"
additionalArgs: []
hostName: autoGeneratedIfEmpty
```
Running: `brudi tarrestore -c ${HOME}/.brudi.yml`
Becomes the following command:
`tar -x -z -f /tmp/test.tar.gz -C /`
##### MongoRestore
```yaml
mongorestore:
options:
flags:
host: 127.0.0.1
port: 27017
username: root
password: mongodbroot
gzip: true
archive: /tmp/dump.tar.gz
additionalArgs: []
```
Running: `brudi mongorestore -c ${HOME}/.brudi.yml `
Becomes the following command:
`mongorestore --host=127.0.0.1 --port=27017 --username=root --password=mongodbroot --gzip --archive=/tmp/dump.tar.gz`
All available flags to be set in the `.yaml`-configuration can be found [here](pkg/source/mongorestore/cli.go#L7).
#### MySQLRestore
```yaml
mysqlrestore:
options:
flags:
host: 127.0.0.1
port: 3306
password: mysqlroot
user: root
Database: test
additionalArgs: []
sourceFile: /tmp/test.sqldump
```
Running: `brudi mysqlrestore -c ${HOME}/.brudi.yml`
Becomes the following command:
`mysql --database=test --host=127.0.0.1 --password=mysqlroot --port=3306 --user=root < /tmp/test.sqldump`
All available flags to be set in the `.yaml`-configuration can be found [here](pkg/source/mysqlrestore/cli.go#L7).
#### PgRestore
Restoration for PostgreSQL databases is split into two commands, `psql` and `pgrestore`. Which one to use depends on the format of the dump created with `pg_dump`:
`psql` can be used to restore plain-text dumps, which is the default format.
`pgrestore` can be used if the `format` option of `pg_dump` was set to `tar`, `directory` or `custom`.
##### Restore using pg_restore
```yaml
pgrestore:
options:
flags:
host: 127.0.0.1
port: 5432
username: postgresuser
password: postgresroot
dbname: postgres
additionalArgs: []
sourcefile: /tmp/postgres.dump
```
Running: `brudi pgrestore -c ${HOME}/.brudi.yml`
Becomes the following command:
`pg_restore --host=127.0.0.1 --port=5432 --username=postgresuser --db-name=postgres /tmp/postgress.dump`
This command has to be used if the `format` option was set to `tar`, `directory` or `custom` in `pg_dump`.
All available flags to be set in the `.yaml`-configuration can be found [here](pkg/source/pgrestore/cli.go#L7).
##### Restore using psql
```yaml
psql:
options:
flags:
host: 127.0.0.1
port: 5432
user: postgresuser
password: postgresroot
dbname: postgres
additionalArgs: []
sourcefile: /tmp/postgres.dump
```
Running: `brudi pgrestore -c ${HOME}/.brudi.yml`
Becomes the following command:
`psql --host=127.0.0.1 --port=5432 --user=postgresuser --db-name=postgres < /tmp/postgress.dump`
This command has to be used if the `format` option was set to `plain` in `pg_dump`, which is the default.
All available flags to be set in the `.yaml`-configuration can be found [here](pkg/source/psql/cli.go#L7).
#### Restoring using restic
Backups can be pulled from a `restic` repository and applied to your server by using the `--restic` flag in your brudi command.
Example configuration for `mongorestore`:
```yaml
mongorestore:
options:
flags:
host: 127.0.0.1
port: 27017
username: root
password: mongodbroot
gzip: true
archive: /tmp/dump.tar.gz
additionalArgs: []
restic:
global:
flags:
repo: "s3:s3.eu-central-1.amazonaws.com/your.s3.bucket/myResticRepo"
restore:
flags:
target: "/"
id: "latest"
```
This will pull the latest snapshot of `/tmp/dump.tar.gz` from the repository, which `mongorestore` then uses to restore the server.
It is also possible to specify concrete snapshot-ids instead of `latest`.
## Featurestate
### Source backup methods
Expand All @@ -378,13 +542,23 @@ As soon as a variable for a key exists in your environment, the value of this en
- [x] `mongodump`
- [x] `tar`
- [x] `pg_dump`
- [x] `redisdump`
### Restore backup methods
- [x] `mysqlrestore`
- [x] `mongorestore`
- [x] `tarrestore`
- [x] `pgrestore`
- [ ] `redisrestore`
### Incremental backup of the source backups
- [x] `restic`
- [x] `commands`
- [x] `restic backup`
- [x] `restic forget`
- [x] `restic restore`
- [x] `restic snapshots`
- [x] `restic prune`
- [x] `restic check`
Expand Down
1 change: 1 addition & 0 deletions build/ci/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ run:
- example/
- .github/
- dist/
- test/
1 change: 0 additions & 1 deletion build/ci/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
before:
hooks:
- go mod download
- make test
- make lint
builds:
-
Expand Down
3 changes: 2 additions & 1 deletion build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ ENV BRUDI_USER="brudi" \
BRUDI_UID="1000"

COPY brudi /usr/local/bin/brudi
COPY --from=restic/restic:0.9.6 /usr/bin/restic /usr/local/bin/restic

COPY --from=restic/restic:0.11.0 /usr/bin/restic /usr/local/bin/restic
COPY --from=redis:alpine /usr/local/bin/redis-cli /usr/local/bin/redis-cli

RUN apk add --no-cache --upgrade \
Expand Down
32 changes: 32 additions & 0 deletions cmd/mongorestore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"context"

"github.com/mittwald/brudi/pkg/source"

"github.com/spf13/cobra"

"github.com/mittwald/brudi/pkg/source/mongorestore"
)

var (
mongoRestoreCmd = &cobra.Command{
Use: "mongorestore",
Short: "restores from mongodump ",
Long: "Restores a given database server with given arguments",
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

err := source.DoRestoreForKind(ctx, mongorestore.Kind, cleanup, useRestic, useResticForget)
if err != nil {
panic(err)
}
},
}
)

func init() {
rootCmd.AddCommand(mongoRestoreCmd)
}
Loading

0 comments on commit e7d3b4e

Please sign in to comment.