Compare commits

..

6 Commits

Author SHA1 Message Date
a3239c0f3b changelog 2021-05-17 22:40:27 +02:00
90cd3171e5 docs 2021-05-17 22:40:23 +02:00
61673bd88b allow options for backend 2021-05-17 22:34:14 +02:00
41736ea3c4 typos 2021-05-07 11:34:46 +02:00
a7779e04bd Merge pull request #75 from FuzzyMistborn/patch-2
Update update command in docs
2021-05-07 11:31:26 +02:00
Fuzzy
1326e7e53c Update update command in docs 2021-05-06 23:05:34 -04:00
11 changed files with 72 additions and 36 deletions

View File

@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.1.1] - 2021-05-17
### Added
- Options for backends
## [1.1.0] - 2021-05-06 ## [1.1.0] - 2021-05-06
### Added ### Added

View File

@@ -22,6 +22,7 @@
> >
> [Overview](/backend/overview) > [Overview](/backend/overview)
> [Available Backends](/backend/available) > [Available Backends](/backend/available)
> [Options](/backend/options)
> :Collapse label=CLI > :Collapse label=CLI
> >
@@ -36,7 +37,7 @@
> [Exec](/cli/exec) > [Exec](/cli/exec)
> [Install](/cli/install) > [Install](/cli/install)
> [Uninstall](/cli/uninstall) > [Uninstall](/cli/uninstall)
> [Update](/cli/update) > [Upgrade](/cli/upgrade)
[Examples](/examples) [Examples](/examples)

View File

@@ -0,0 +1,23 @@
# Options
For the `backup` and `forget` commands you can pass any native flags to `restic`.
> It is also possible to set options for an [a specific location](/location/options).
```yaml
backend:
foo:
type: ...
path: ...
options:
backup:
tag:
- foo
- bar
```
In this example, whenever `autorestic` runs `restic backup` it will append a `--tag abc --tag` to the native command.
For more detail see the [location docs](/location/options) for options, as they are the same
> :ToCPrevNext

View File

@@ -4,7 +4,7 @@
autorestic forget [-l, --location] [-a, --all] [--dry-run] [--prune] autorestic forget [-l, --location] [-a, --all] [--dry-run] [--prune]
``` ```
This will prune and remove old data form the backends according to the [keep policy you have specified for the location](/location/forget) This will prune and remove old data form the backends according to the [keep policy you have specified for the location](/location/forget).
The `--dry-run` flag will do a dry run showing what would have been deleted, but won't touch the actual data. The `--dry-run` flag will do a dry run showing what would have been deleted, but won't touch the actual data.

View File

@@ -1,11 +0,0 @@
# Update
Autorestic can update itself! Super handy right? Simply run autorestic update and we will check for you if there are updates for restic and autorestic and install them if necessary.
```bash
autorestic update
```
Updates both restic and autorestic automagically.
> :ToCPrevNext

View File

@@ -0,0 +1,11 @@
# Upgrade
Autorestic can upgrade itself! Super handy right? Simply run autorestic upgrade and we will check for you if there are updates for restic and autorestic and install them if necessary.
```bash
autorestic upgrade
```
Updates both restic and autorestic automagically.
> :ToCPrevNext

View File

@@ -2,6 +2,8 @@
For the `backup` and `forget` commands you can pass any native flags to `restic`. For the `backup` and `forget` commands you can pass any native flags to `restic`.
> It is also possible to set options for an [entire backend](/backend/options).
```yaml ```yaml
locations: locations:
foo: foo:

View File

@@ -1,4 +1,4 @@
# Update # Upgrade
## From `0.x` to `1.0` ## From `0.x` to `1.0`

View File

@@ -17,12 +17,13 @@ type BackendRest struct {
} }
type Backend struct { type Backend struct {
name string name string
Type string `yaml:"type,omitempty"` Type string `yaml:"type,omitempty"`
Path string `yaml:"path,omitempty"` Path string `yaml:"path,omitempty"`
Key string `yaml:"key,omitempty"` Key string `yaml:"key,omitempty"`
Env map[string]string `yaml:"env,omitempty"` Env map[string]string `yaml:"env,omitempty"`
Rest BackendRest `yaml:"rest,omitempty"` Rest BackendRest `yaml:"rest,omitempty"`
Options Options `yaml:"options,omitempty"`
} }
func GetBackend(name string) (Backend, bool) { func GetBackend(name string) (Backend, bool) {

View File

@@ -12,7 +12,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const VERSION = "1.1.0" const VERSION = "1.1.1"
var CI bool = false var CI bool = false
var VERBOSE bool = false var VERBOSE bool = false
@@ -220,3 +220,13 @@ func (c *Config) SaveConfig() error {
return viper.WriteConfig() return viper.WriteConfig()
} }
func getOptions(options Options, key string) []string {
var selected []string
for k, values := range options[key] {
for _, value := range values {
selected = append(selected, fmt.Sprintf("--%s", k), value)
}
}
return selected
}

View File

@@ -78,17 +78,6 @@ func (l Location) validate(c *Config) error {
return nil return nil
} }
func (l Location) getOptions(key string) []string {
var options []string
saved := l.Options[key]
for k, values := range saved {
for _, value := range values {
options = append(options, fmt.Sprintf("--%s", k), value)
}
}
return options
}
func ExecuteHooks(commands []string, options ExecuteOptions) error { func ExecuteHooks(commands []string, options ExecuteOptions) error {
if len(commands) == 0 { if len(commands) == 0 {
return nil return nil
@@ -164,9 +153,11 @@ func (l Location) Backup(cron bool) []error {
continue continue
} }
flags := l.getOptions("backup") lFlags := getOptions(l.Options, "backup")
bFlags := getOptions(backend.Options, "backup")
cmd := []string{"backup"} cmd := []string{"backup"}
cmd = append(cmd, flags...) cmd = append(cmd, lFlags...)
cmd = append(cmd, bFlags...)
if cron { if cron {
cmd = append(cmd, "--tag", "cron") cmd = append(cmd, "--tag", "cron")
} }
@@ -232,7 +223,8 @@ func (l Location) Forget(prune bool, dry bool) error {
options := ExecuteOptions{ options := ExecuteOptions{
Envs: env, Envs: env,
} }
flags := l.getOptions("forget") lFlags := getOptions(l.Options, "forget")
bFlags := getOptions(backend.Options, "forget")
cmd := []string{"forget", "--path", path} cmd := []string{"forget", "--path", path}
if prune { if prune {
cmd = append(cmd, "--prune") cmd = append(cmd, "--prune")
@@ -240,7 +232,8 @@ func (l Location) Forget(prune bool, dry bool) error {
if dry { if dry {
cmd = append(cmd, "--dry-run") cmd = append(cmd, "--dry-run")
} }
cmd = append(cmd, flags...) cmd = append(cmd, lFlags...)
cmd = append(cmd, bFlags...)
out, err := ExecuteResticCommand(options, cmd...) out, err := ExecuteResticCommand(options, cmd...)
if VERBOSE { if VERBOSE {
colors.Faint.Println(out) colors.Faint.Println(out)