Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cupcakearmy committed Dec 9, 2022
2 parents d6acab9 + d0d2fcf commit ec61eff
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 13 deletions.
5 changes: 4 additions & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import (
var DIR, _ = filepath.Abs("./dist")

var targets = map[string][]string{
// "aix": {"ppc64"}, // Not supported by fsnotify
"darwin": {"amd64", "arm64"},
"freebsd": {"386", "amd64", "arm"},
"linux": {"386", "amd64", "arm", "arm64"},
"linux": {"386", "amd64", "arm", "arm64", "ppc64le", "mips", "mipsle", "mips64", "mips64le", "s390x"},
"netbsd": {"386", "amd64"},
"openbsd": {"386", "amd64"},
// "windows": {"386", "amd64"}, // Not supported by autorestic
"solaris": {"amd64"},
}

type buildOptions struct {
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&flags.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity")
rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode")
rootCmd.PersistentFlags().StringVar(&flags.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
rootCmd.PersistentFlags().StringVar(&flags.DOCKER_IMAGE, "docker-image", "cupcakearmy/autorestic:"+internal.VERSION, "specify a custom docker image")
cobra.OnInitialize(initConfig)
}

Expand Down
1 change: 1 addition & 0 deletions docs/markdown/community.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ A list of community driven projects. (No official affiliation)
- Ansible Role: <https://github.com/ItsNotGoodName/ansible-role-autorestic>
- Ansible Role: <https://github.com/FuzzyMistborn/ansible-role-autorestic>
- Ansible Role: <https://0xacab.org/varac-projects/ansible-role-autorestic>
- Ansible Role: <https://github.com/dbrennand/ansible-role-autorestic>

> :ToCPrevNext
2 changes: 1 addition & 1 deletion docs/markdown/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Linux & macOS. Windows is not supported. If you have problems installing please
Autorestic requires `bash`, `wget` and `bzip2` to be installed. For most systems these should be already installed.

```bash
wget -qO - https://raw.githubusercontent.com/CupCakeArmy/autorestic/master/install.sh | bash
wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash
```

## Alternatives
Expand Down
2 changes: 1 addition & 1 deletion docs/markdown/location/forget.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ locations:
keep-weekly: 1 # keep 1 last weekly snapshots
keep-monthly: 12 # keep 12 last monthly snapshots
keep-yearly: 7 # keep 7 last yearly snapshots
keep-within: '2w' # keep snapshots from the last 2 weeks
keep-within: '14d' # keep snapshots from the last 14 days
```

## Globally
Expand Down
2 changes: 1 addition & 1 deletion docs/markdown/quick.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Installation

```bash
wget -qO - https://raw.githubusercontent.com/CupCakeArmy/autorestic/master/install.sh | bash
wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash
```

See [installation](/installation) for alternative options.
Expand Down
5 changes: 5 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ else
fi
echo $ARCH

if ! command -v bzip2 &>/dev/null; then
echo "Missing bzip2 command. Please install the bzip2 package for your system."
exit 1
fi

wget -qO - https://api.github.com/repos/cupcakearmy/autorestic/releases/latest \
| grep "browser_download_url.*_${OS}_${ARCH}" \
| cut -d : -f 2,3 \
Expand Down
13 changes: 9 additions & 4 deletions internal/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/cupcakearmy/autorestic/internal/colors"
"github.com/cupcakearmy/autorestic/internal/flags"
)

type BackendRest struct {
Expand Down Expand Up @@ -121,13 +122,17 @@ func (b Backend) validate() error {
}
options := ExecuteOptions{Envs: env, Silent: true}
// Check if already initialized
_, _, err = ExecuteResticCommand(options, "check")
cmd := []string{"check"}
cmd = append(cmd, combineBackendOptions("check", b)...)
_, _, err = ExecuteResticCommand(options, cmd...)
if err == nil {
return nil
} else {
// If not initialize
colors.Body.Printf("Initializing backend \"%s\"...\n", b.name)
_, _, err := ExecuteResticCommand(options, "init")
cmd := []string{"init"}
cmd = append(cmd, combineBackendOptions("init", b)...)
_, _, err := ExecuteResticCommand(options, cmd...)
return err
}
}
Expand Down Expand Up @@ -160,7 +165,6 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) {
args = append([]string{"restic"}, args...)
docker := []string{
"run", "--rm",
"--pull", "always",
"--entrypoint", "ash",
"--workdir", dir,
"--volume", volume + ":" + dir,
Expand Down Expand Up @@ -194,6 +198,7 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) {
for key, value := range env {
docker = append(docker, "--env", key+"="+value)
}
docker = append(docker, "cupcakearmy/autorestic:"+VERSION, "-c", strings.Join(args, " "))

docker = append(docker, flags.DOCKER_IMAGE, "-c", strings.Join(args, " "))
return ExecuteCommand(options, docker...)
}
14 changes: 12 additions & 2 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/spf13/viper"
)

const VERSION = "1.7.2"
const VERSION = "1.7.4"

type OptionMap map[string][]interface{}
type Options map[string]OptionMap
Expand Down Expand Up @@ -303,7 +303,17 @@ func getOptions(options Options, keys []string) []string {
return selected
}

func combineOptions(key string, l Location, b Backend) []string {
func combineBackendOptions(key string, b Backend) []string {
// Priority: backend > global
var options []string
gFlags := getOptions(GetConfig().Global, []string{key})
bFlags := getOptions(b.Options, []string{"all", key})
options = append(options, gFlags...)
options = append(options, bFlags...)
return options
}

func combineAllOptions(key string, l Location, b Backend) []string {
// Priority: location > backend > global
var options []string
gFlags := getOptions(GetConfig().Global, []string{key})
Expand Down
1 change: 1 addition & 0 deletions internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ var (
VERBOSE bool = false
CRON_LEAN bool = false
RESTIC_BIN string
DOCKER_IMAGE string
)
9 changes: 6 additions & 3 deletions internal/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
}

cmd := []string{"backup"}
cmd = append(cmd, combineOptions("backup", l, backend)...)
cmd = append(cmd, combineAllOptions("backup", l, backend)...)
if cron {
cmd = append(cmd, "--tag", buildTag("cron"))
}
Expand Down Expand Up @@ -308,7 +308,10 @@ after:

// Forget and optionally prune
if isSuccess && l.ForgetOption != "" && l.ForgetOption != LocationForgetNo {
l.Forget(l.ForgetOption == LocationForgetPrune, false)
err := l.Forget(l.ForgetOption == LocationForgetPrune, false)
if err != nil {
errors = append(errors, err)
}
}

if len(errors) == 0 {
Expand Down Expand Up @@ -342,7 +345,7 @@ func (l Location) Forget(prune bool, dry bool) error {
if dry {
cmd = append(cmd, "--dry-run")
}
cmd = append(cmd, combineOptions("forget", l, backend)...)
cmd = append(cmd, combineAllOptions("forget", l, backend)...)
_, _, err = ExecuteResticCommand(options, cmd...)
if err != nil {
return err
Expand Down

0 comments on commit ec61eff

Please sign in to comment.