Compare commits

...

11 Commits

Author SHA1 Message Date
86ae70672a right version 2021-08-05 21:58:48 +02:00
5c0788900f docs 2021-08-05 21:54:40 +02:00
20334a7e83 better config handling 2021-08-05 21:48:02 +02:00
7bebd04482 validate and show cwd 2021-07-12 19:10:36 +02:00
b9b8857bf4 aliases 2021-07-12 19:10:25 +02:00
dd6e618161 typo 2021-07-11 14:03:04 +02:00
a4b54f9f64 check config bugs 2021-07-11 13:51:04 +02:00
c2e88193cd Update contrib.md 2021-06-06 15:51:50 +02:00
a2ef69d96d Merge pull request #87 from somebox/patch-1
correction to B2 config in the example
2021-06-06 15:48:02 +02:00
Jeremy Seitz
d45949b028 correction to B2 config in the example
This example was missing the `env:` block in YAML, which if missing, caused `autorestic check` to compain:

``` * 'Backends[remote]' has invalid keys: b2_account_id, b2_account_key```
2021-06-06 14:27:26 +02:00
77d47cc697 add arm in install script 2021-05-25 22:57:42 +02:00
13 changed files with 172 additions and 796 deletions

View File

@@ -5,6 +5,24 @@ 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.2.0] - 2021-08-05
### Added
- Community page
- Support for yaml references and aliases
### Fixed
- Better verbose output for hooks
- Better error message for bad formatted configs
## [1.1.2] - 2021-07-11
### Fixes
Don't check all backend when running `forget` or `exec` commands.
## [1.1.1] - 2021-05-17 ## [1.1.1] - 2021-05-17
### Added ### Added

View File

@@ -19,7 +19,7 @@ Releases are automatically built by the github workflow and uploaded to the rele
1. Bump `VERSION` in `internal/config.go`. 1. Bump `VERSION` in `internal/config.go`.
2. Update `CHANGELOG.md` 2. Update `CHANGELOG.md`
3. Commit to master 3. Commit to master
4. Create a new release with the `v1.2.3` tag and mark as draft. 4. Create a new release with the `v1.2.3` tag and mark as pre-release.
5. The Github action will build the binaries, upload and mark the release as ready when done. 5. The Github action will build the binaries, upload and mark the release as ready when done.
### Brew ### Brew

View File

@@ -13,12 +13,11 @@ var backupCmd = &cobra.Command{
Use: "backup", Use: "backup",
Short: "Create backups for given locations", Short: "Create backups for given locations",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
internal.GetConfig()
err := lock.Lock() err := lock.Lock()
CheckErr(err) CheckErr(err)
defer lock.Unlock() defer lock.Unlock()
internal.GetConfig()
selected, err := internal.GetAllOrSelected(cmd, false) selected, err := internal.GetAllOrSelected(cmd, false)
CheckErr(err) CheckErr(err)
errors := 0 errors := 0

View File

@@ -11,12 +11,11 @@ var execCmd = &cobra.Command{
Use: "exec", Use: "exec",
Short: "Execute arbitrary native restic commands for given backends", Short: "Execute arbitrary native restic commands for given backends",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
internal.GetConfig()
err := lock.Lock() err := lock.Lock()
CheckErr(err) CheckErr(err)
defer lock.Unlock() defer lock.Unlock()
CheckErr(internal.CheckConfig())
selected, err := internal.GetAllOrSelected(cmd, true) selected, err := internal.GetAllOrSelected(cmd, true)
CheckErr(err) CheckErr(err)
for _, name := range selected { for _, name := range selected {

View File

@@ -10,12 +10,11 @@ var forgetCmd = &cobra.Command{
Use: "forget", Use: "forget",
Short: "Forget and optionally prune snapshots according the specified policies", Short: "Forget and optionally prune snapshots according the specified policies",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
internal.GetConfig()
err := lock.Lock() err := lock.Lock()
CheckErr(err) CheckErr(err)
defer lock.Unlock() defer lock.Unlock()
CheckErr(internal.CheckConfig())
selected, err := internal.GetAllOrSelected(cmd, false) selected, err := internal.GetAllOrSelected(cmd, false)
CheckErr(err) CheckErr(err)
prune, _ := cmd.Flags().GetBool("prune") prune, _ := cmd.Flags().GetBool("prune")

View File

@@ -40,7 +40,7 @@
> [Upgrade](/cli/upgrade) > [Upgrade](/cli/upgrade)
[Examples](/examples) [Examples](/examples)
[QA](/qa) [QA](/qa)
[Community](/community)
[Contributors](/contrib) [Contributors](/contrib)

View File

@@ -0,0 +1,9 @@
# 🏘 Community
A list of community driven projects. (No official affiliation)
- Docker image: https://github.com/pascaliske/docker-autorestic
- Ansible Role: https://github.com/adsanz/ansible-restic-role
- Ansible Role: https://github.com/ItsNotGoodName/ansible-role-autorestic
> :ToCPrevNext

View File

@@ -31,12 +31,53 @@ backends:
remote: remote:
type: b2 type: b2
path: 'myBucket:backup/home' path: 'myBucket:backup/home'
B2_ACCOUNT_ID: account_id env:
B2_ACCOUNT_KEY: account_key B2_ACCOUNT_ID: account_id
B2_ACCOUNT_KEY: account_key
hdd: hdd:
type: local type: local
path: /mnt/my_external_storage path: /mnt/my_external_storage
``` ```
## Aliases
A handy tool for more advanced configurations is to use yaml aliases.
These must be specified under the global `extras` key in the `.autorestic.yml` config file.
Aliases allow to reuse snippets of config throughout the same file.
The following example shows how the locations `a` and `b` share the same hooks and forget policies.
```yaml | .autorestic.yml
extras:
hooks: &foo
before:
- echo "Hello"
after:
- echo "kthxbye"
policies: &bar
keep-daily: 14
keep-weekly: 52
backends:
# ...
locations:
a:
from: /data/a
to: some
hooks:
<<: *foo
options:
forget:
<<: *bar
b:
from: data/b
to: some
hooks:
<<: *foo
options:
forget:
<<: *bar
```
> :ToCPrevNext > :ToCPrevNext

View File

@@ -12,5 +12,6 @@ This amazing people helped the project!
- @ChanceM - Typos - @ChanceM - Typos
- @TheForcer - Typos - @TheForcer - Typos
- @themorlan - Typos - @themorlan - Typos
- @somebox - Typos
> :ToCPrevNext > :ToCPrevNext

854
docs/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,8 @@ elif [[ $NATIVE_ARCH == *"arm64"* || $NATIVE_ARCH == *"aarch64"* ]]; then
ARCH=arm64 ARCH=arm64
elif [[ $NATIVE_ARCH == *"x86"* ]]; then elif [[ $NATIVE_ARCH == *"x86"* ]]; then
ARCH=386 ARCH=386
elif [[ $NATIVE_ARCH == *"armv7"* ]]; then
ARCH=arm
else else
echo "Could not determine Architecure automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases" echo "Could not determine Architecure automatically, please check the release page manually: https://github.com/cupcakearmy/autorestic/releases"
exit 1 exit 1

View File

@@ -2,23 +2,27 @@ package internal
import ( import (
"fmt" "fmt"
"os"
"path" "path"
"path/filepath"
"strings" "strings"
"sync" "sync"
"github.com/cupcakearmy/autorestic/internal/colors" "github.com/cupcakearmy/autorestic/internal/colors"
"github.com/cupcakearmy/autorestic/internal/lock"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const VERSION = "1.1.1" const VERSION = "1.2.0"
var CI bool = false var CI bool = false
var VERBOSE bool = false var VERBOSE bool = false
var CRON_LEAN bool = false var CRON_LEAN bool = false
type Config struct { type Config struct {
Extras interface{} `yaml:"extras"`
Locations map[string]Location `yaml:"locations"` Locations map[string]Location `yaml:"locations"`
Backends map[string]Backend `yaml:"backends"` Backends map[string]Backend `yaml:"backends"`
} }
@@ -31,7 +35,8 @@ func GetConfig() *Config {
once.Do(func() { once.Do(func() {
if err := viper.ReadInConfig(); err == nil { if err := viper.ReadInConfig(); err == nil {
if !CRON_LEAN { if !CRON_LEAN {
colors.Faint.Println("Using config file:", viper.ConfigFileUsed()) absConfig, _ := filepath.Abs(viper.ConfigFileUsed())
colors.Faint.Println("Using config file:", absConfig)
} }
} else { } else {
return return
@@ -39,7 +44,9 @@ func GetConfig() *Config {
config = &Config{} config = &Config{}
if err := viper.UnmarshalExact(config); err != nil { if err := viper.UnmarshalExact(config); err != nil {
panic(err) colors.Error.Println("Could not parse config file!")
lock.Unlock()
os.Exit(1)
} }
}) })
} }
@@ -140,7 +147,7 @@ func CheckConfig() error {
} }
for name, location := range c.Locations { for name, location := range c.Locations {
location.name = name location.name = name
if err := location.validate(c); err != nil { if err := location.validate(); err != nil {
return err return err
} }
} }

View File

@@ -47,7 +47,7 @@ func GetLocation(name string) (Location, bool) {
return l, ok return l, ok
} }
func (l Location) validate(c *Config) error { func (l Location) validate() error {
if l.From == "" { if l.From == "" {
return fmt.Errorf(`Location "%s" is missing "from" key`, l.name) return fmt.Errorf(`Location "%s" is missing "from" key`, l.name)
} }
@@ -132,8 +132,15 @@ func (l Location) Backup(cron bool) []error {
Command: "bash", Command: "bash",
} }
if err := l.validate(); err != nil {
errors = append(errors, err)
colors.Error.Print(err)
goto after
}
if t == TypeLocal { if t == TypeLocal {
dir, _ := GetPathRelativeToConfig(l.From) dir, _ := GetPathRelativeToConfig(l.From)
colors.Faint.Printf("Executing under: \"%s\"\n", dir)
options.Dir = dir options.Dir = dir
} }