Skip to content

Commit

Permalink
Merge branch 'release/0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
syaiful6 committed Jan 9, 2022
2 parents e1c642e + c7144e5 commit 3e1082f
Show file tree
Hide file tree
Showing 39 changed files with 1,282 additions and 390 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
*.o
*.a
*.so
*.yml
payung-local.yml
!payung-reference.yml
!.github/goreleaser.yml
.DS_Store
payung
/payung

dist/
36 changes: 36 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
-
main: ./cmd/payung
ldflags:
- -s -w -X github.com/syaiful6/payung/version.Version={{.Version}} -X github.com/syaiful6/payung/version.Revision={{.Commit}}
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ GO_GCFLAGS :=
default: build

build:
go build -o payung -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS)
go build -o payung -tags "$(BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" $(GO_GCFLAGS) ./cmd/payung
104 changes: 102 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
# Payung

Payung is a system utility for Linux, Mac OS X and BSD.
Payung is a system utility backup for Linux, Mac OS X and BSD.

This project has beed forked from (gobackup)[https://github.com/huacnlee/gobackup] since 2020.
This project has beed forked from [gobackup](https://github.com/huacnlee/gobackup) since 2020.

## Current support status

### Databases

- MySQL
- PostgreSQL
- Redis
- MongoDB

### Compressor
- Gzip
- Brotli

### Storages
- Local
- FTP
- SCP
- Amazon S3
- Alibaba Cloud Object Storage Service (OSS)
- Dropbox

### Notification
- Slack

## Installation

Currently we don't provides binary release, you need to compile it from source yourself.

- Clone this repository: `git clone https://github.com/syaiful6/payung.git`
- Build the binary: `make build`
- Copy the output binary: `payung` to your PATH: `sudo cp payung /usr/local/bin`

## Configuration

Payung will seek config files in:
- ~/.payung/payung.yml
- /etc/payung/payung.yml

Example config file: [payung-reference.yml](https://github.com/syaiful6/payung/blob/develop/payung-reference.yml).

```yml
models:
gitlab:
compress_with:
type: brotli
level: 8
store_with:
type: s3
bucket: backups
region: us-east-1
access_key_id: xxxxxx
secret_access_key: xxxxxxx
max_retries: 5
notify_with:
slack:
type: slack
webhook_url: https://hooks.slack.com/services/xxxxx
channel: database_backups
send_on:
- success
- failed
databases:
gitlab:
type: mysql
host: localhost
port: 3306
database: gitlab
username: root
password: xxxxxx
additional_options: --single-transaction --quick --max_allowed_packet=1G
archive:
includes:
- /home/git/.ssh/
- /etc/mysql/my.conf
- /etc/logrotate.d/
excludes:
- /home/ubuntu/.ssh/known_hosts
- /etc/logrotate.d/syslog
```
## Usage
You can learn available options with `payung --help` and `payung perform --help`.

For example this is how you provides custom config file and dump path folder.

```
payung perform -c ~/backups/payung.yml -d ~/backups/workdir
```
We recommend you to perform backups using cron, here are an example configuration:
```
5 0 * * * /usr/local/bin/payung perform -c /home/ubuntu/payung.yml -d /mnt/ebs/backups >> /mnt/ebs/backups/backup.log 2>&1
```
### Recommendation
If you use Amazon S3, we recommends to use [AWS S3 object lifecycle](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html) instead of our storage lifecycle. You can use it to move the object to Glacier or delete the backups if older than one month.
11 changes: 9 additions & 2 deletions archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,21 @@ func Run(model config.ModelConfig) (err error) {
return fmt.Errorf("-> can't archive files: %s", err)
}
archiveFilePath := path.Join(model.DumpPath, "archive.tar")
err, ext, r := compressor.CompressTo(model, bufio.NewReader(stdoutPipe))
ext, r, err := compressor.CompressTo(model, bufio.NewReader(stdoutPipe))
if err != nil {
return fmt.Errorf("-> can't compress tar output: %s", err)
}
archiveFilePath = archiveFilePath + ext
f, err := os.Create(archiveFilePath + ".br")
f, err := os.Create(archiveFilePath)
if err != nil {
return err
}

defer f.Close()
_, err = io.Copy(f, r)
if err != nil {
return err
}

if err = tarCmd.Wait(); err != nil {
return fmt.Errorf("-> archive error: %s", err)
Expand Down
34 changes: 34 additions & 0 deletions cmd/payung/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"github.com/spf13/cobra"
"github.com/syaiful6/payung/version"
)

// show application version number
var showVersion bool

func main() {
execute()
}

func execute() error {
// Rootcmd is the rootcommand for
var rootCmd = &cobra.Command{
Use: "Payung",
Short: "Easy full stack backup operations on UNIX-like systems.",
Long: `Easy full stack backup operations on UNIX-like systems.`,
Run: func(cmd *cobra.Command, args []string) {
if showVersion {
version.PrintVersion()
return
}
cmd.Usage()
},
}
rootCmd.Flags().BoolVarP(&showVersion, "version", "v", false, "Print payung's current version")
rootCmd.AddCommand(performCmd())
rootCmd.AddCommand(decompressCommand())

return rootCmd.Execute()
}
55 changes: 55 additions & 0 deletions cmd/payung/perform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"github.com/spf13/cobra"
"github.com/syaiful6/payung/config"
"github.com/syaiful6/payung/model"
)

func performCmd() *cobra.Command {
var (
modelName string
configFile string
dumpPath string
)
var performCommand = &cobra.Command{
Use: "perform",
Short: `Perform backup`,
Long: `Perform backup`,
RunE: func(cmd *cobra.Command, args []string) error {
config.Init(configFile, dumpPath)
if len(modelName) == 0 {
performAll()
} else {
performOne(modelName)
}

return nil
},
}
performCommand.Flags().StringVarP(&modelName, "model", "m", "", "Model name that you want execute")
performCommand.Flags().StringVarP(&configFile, "config", "c", "", "Special a config file")
performCommand.Flags().StringVarP(&dumpPath, "dumpfile", "d", "", "special Dump path folder")
return performCommand
}

func performAll() {
for _, modelConfig := range config.Models {
m := model.Model{
Config: modelConfig,
}
m.Perform()
}
}

func performOne(modelName string) {
for _, modelConfig := range config.Models {
if modelConfig.Name == modelName {
m := model.Model{
Config: modelConfig,
}
m.Perform()
return
}
}
}
Loading

0 comments on commit 3e1082f

Please sign in to comment.