mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-06 10:30:39 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
5afad86e37 | |||
ba9e090695 | |||
|
05def04770 | ||
d85470459f | |||
1f69a7974a | |||
db9f5dea66 | |||
75160d4d6a | |||
92feaef5bb | |||
2a7e233cdb |
28
CHANGELOG.md
28
CHANGELOG.md
@@ -5,6 +5,34 @@ 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.5.6] - 2022-03-10
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Add bash in docker image for hooks. @fariszr
|
||||||
|
|
||||||
|
## [1.5.5] - 2022-02-16
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Go version was updated from `1.16` to `1.17`
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Home directory was not being taken into account for loading configs.
|
||||||
|
|
||||||
|
## [1.5.4] - 2022-02-16
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Lean flag not omitting all output.
|
||||||
|
|
||||||
|
## [1.5.3] - 2022-02-16
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Error throwing not finding config even it's not being used.
|
||||||
|
|
||||||
## [1.5.2] - 2022-02-13
|
## [1.5.2] - 2022-02-13
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.16-alpine as builder
|
FROM golang:1.17-alpine as builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY go.* .
|
COPY go.* .
|
||||||
@@ -7,6 +7,6 @@ COPY . .
|
|||||||
RUN go build
|
RUN go build
|
||||||
|
|
||||||
FROM alpine
|
FROM alpine
|
||||||
RUN apk add --no-cache restic rclone
|
RUN apk add --no-cache restic rclone bash
|
||||||
COPY --from=builder /app/autorestic /usr/bin/autorestic
|
COPY --from=builder /app/autorestic /usr/bin/autorestic
|
||||||
CMD [ "autorestic" ]
|
CMD [ "autorestic" ]
|
||||||
|
@@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cupcakearmy/autorestic/internal"
|
"github.com/cupcakearmy/autorestic/internal"
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -12,7 +13,7 @@ var cronCmd = &cobra.Command{
|
|||||||
Long: `Intended to be mainly triggered by an automated system like systemd or crontab. For each location checks if a cron backup is due and runs it.`,
|
Long: `Intended to be mainly triggered by an automated system like systemd or crontab. For each location checks if a cron backup is due and runs it.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
internal.GetConfig()
|
internal.GetConfig()
|
||||||
internal.CRON_LEAN, _ = cmd.Flags().GetBool("lean")
|
flags.CRON_LEAN, _ = cmd.Flags().GetBool("lean")
|
||||||
err := lock.Lock()
|
err := lock.Lock()
|
||||||
CheckErr(err)
|
CheckErr(err)
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
|
26
cmd/root.go
26
cmd/root.go
@@ -1,13 +1,13 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal"
|
"github.com/cupcakearmy/autorestic/internal"
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ func Execute() {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.autorestic.yml or ./.autorestic.yml)")
|
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.autorestic.yml or ./.autorestic.yml)")
|
||||||
rootCmd.PersistentFlags().BoolVar(&internal.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity")
|
rootCmd.PersistentFlags().BoolVar(&flags.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&internal.VERBOSE, "verbose", "v", false, "verbose mode")
|
rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode")
|
||||||
rootCmd.PersistentFlags().StringVar(&internal.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
|
rootCmd.PersistentFlags().StringVar(&internal.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
}
|
}
|
||||||
@@ -47,13 +47,10 @@ func init() {
|
|||||||
func initConfig() {
|
func initConfig() {
|
||||||
if ci, _ := rootCmd.Flags().GetBool("ci"); ci {
|
if ci, _ := rootCmd.Flags().GetBool("ci"); ci {
|
||||||
colors.DisableColors(true)
|
colors.DisableColors(true)
|
||||||
internal.VERBOSE = true
|
flags.VERBOSE = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
if internal.VERBOSE {
|
|
||||||
colors.Faint.Printf("> Using config file: %s\n", cfgFile)
|
|
||||||
}
|
|
||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
if viper.ConfigFileUsed() == "" {
|
if viper.ConfigFileUsed() == "" {
|
||||||
@@ -64,7 +61,7 @@ func initConfig() {
|
|||||||
configPaths := []string{"."}
|
configPaths := []string{"."}
|
||||||
|
|
||||||
// Home
|
// Home
|
||||||
if home, err := homedir.Dir(); err != nil {
|
if home, err := homedir.Dir(); err == nil {
|
||||||
configPaths = append(configPaths, home)
|
configPaths = append(configPaths, home)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,20 +77,13 @@ func initConfig() {
|
|||||||
configPaths = append(configPaths, xdgConfig)
|
configPaths = append(configPaths, xdgConfig)
|
||||||
}
|
}
|
||||||
for _, cfgPath := range configPaths {
|
for _, cfgPath := range configPaths {
|
||||||
if internal.VERBOSE {
|
|
||||||
colors.Faint.Printf("> Adding config path: '%s'\n", cfgPath)
|
|
||||||
}
|
|
||||||
viper.AddConfigPath(cfgPath)
|
viper.AddConfigPath(cfgPath)
|
||||||
}
|
}
|
||||||
|
if flags.VERBOSE {
|
||||||
|
colors.Faint.Printf("Using config paths: %s\n", strings.Join(configPaths, " "))
|
||||||
|
}
|
||||||
cfgFileName := ".autorestic"
|
cfgFileName := ".autorestic"
|
||||||
viper.SetConfigName(cfgFileName)
|
viper.SetConfigName(cfgFileName)
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
if viper.ConfigFileUsed() == "" {
|
|
||||||
colors.Error.Println(
|
|
||||||
fmt.Sprintf(
|
|
||||||
"cannot find configuration file '%s.yml' or '%s.yaml' in config paths: ['%s']",
|
|
||||||
cfgFileName, cfgFileName, strings.Join(configPaths, "', '")))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ This amazing people helped the project!
|
|||||||
- @agateblue - Docs, Pruning, S3.
|
- @agateblue - Docs, Pruning, S3.
|
||||||
- @g-a-c - Update/Install bugs.
|
- @g-a-c - Update/Install bugs.
|
||||||
- @jjromannet - Bug fixes.
|
- @jjromannet - Bug fixes.
|
||||||
|
- @fariszr - Bug fixes.
|
||||||
- @david-boles - Docs.
|
- @david-boles - Docs.
|
||||||
- @SebDanielsson - Brew.
|
- @SebDanielsson - Brew.
|
||||||
- @n194 - AUR Package.
|
- @n194 - AUR Package.
|
||||||
|
22
go.mod
22
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/cupcakearmy/autorestic
|
module github.com/cupcakearmy/autorestic
|
||||||
|
|
||||||
go 1.16
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/blang/semver/v4 v4.0.0
|
github.com/blang/semver/v4 v4.0.0
|
||||||
@@ -12,3 +12,23 @@ require (
|
|||||||
github.com/spf13/cobra v1.1.3
|
github.com/spf13/cobra v1.1.3
|
||||||
github.com/spf13/viper v1.7.1
|
github.com/spf13/viper v1.7.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7 // indirect
|
||||||
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
|
github.com/magiconair/properties v1.8.1 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.12 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.1.2 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.2.0 // indirect
|
||||||
|
github.com/spf13/afero v1.1.2 // indirect
|
||||||
|
github.com/spf13/cast v1.3.0 // indirect
|
||||||
|
github.com/spf13/jwalterweatherman v1.0.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
github.com/subosito/gotenv v1.2.0 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54 // indirect
|
||||||
|
golang.org/x/text v0.3.2 // indirect
|
||||||
|
gopkg.in/ini.v1 v1.51.0 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
)
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BackendRest struct {
|
type BackendRest struct {
|
||||||
@@ -128,7 +129,7 @@ func (b Backend) validate() error {
|
|||||||
// If not initialize
|
// If not initialize
|
||||||
colors.Body.Printf("Initializing backend \"%s\"...\n", b.name)
|
colors.Body.Printf("Initializing backend \"%s\"...\n", b.name)
|
||||||
out, err := ExecuteResticCommand(options, "init")
|
out, err := ExecuteResticCommand(options, "init")
|
||||||
if VERBOSE {
|
if flags.VERBOSE {
|
||||||
colors.Faint.Println(out)
|
colors.Faint.Println(out)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -146,7 +147,7 @@ func (b Backend) Exec(args []string) error {
|
|||||||
colors.Error.Println(out)
|
colors.Error.Println(out)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if VERBOSE {
|
if flags.VERBOSE {
|
||||||
colors.Faint.Println(out)
|
colors.Faint.Println(out)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
@@ -16,11 +17,7 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "1.5.2"
|
const VERSION = "1.5.6"
|
||||||
|
|
||||||
var CI bool = false
|
|
||||||
var VERBOSE bool = false
|
|
||||||
var CRON_LEAN bool = false
|
|
||||||
|
|
||||||
type OptionMap map[string][]interface{}
|
type OptionMap map[string][]interface{}
|
||||||
type Options map[string]OptionMap
|
type Options map[string]OptionMap
|
||||||
@@ -52,18 +49,23 @@ func GetConfig() *Config {
|
|||||||
if config == nil {
|
if config == nil {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
if err := viper.ReadInConfig(); err == nil {
|
||||||
if !CRON_LEAN {
|
absConfig, _ := filepath.Abs(viper.ConfigFileUsed())
|
||||||
absConfig, _ := filepath.Abs(viper.ConfigFileUsed())
|
if !flags.CRON_LEAN {
|
||||||
colors.Faint.Println("Using config: \t", absConfig)
|
colors.Faint.Println("Using config: \t", absConfig)
|
||||||
// Load env file
|
}
|
||||||
envFile := filepath.Join(filepath.Dir(absConfig), ".autorestic.env")
|
// Load env file
|
||||||
err = godotenv.Load(envFile)
|
envFile := filepath.Join(filepath.Dir(absConfig), ".autorestic.env")
|
||||||
if err == nil {
|
err = godotenv.Load(envFile)
|
||||||
colors.Faint.Println("Using env:\t", envFile)
|
if err == nil {
|
||||||
}
|
colors.Faint.Println("Using env:\t", envFile)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return
|
cfgFileName := ".autorestic"
|
||||||
|
colors.Error.Println(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"cannot find configuration file '%s.yml' or '%s.yaml'.",
|
||||||
|
cfgFileName, cfgFileName))
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionConfig interface{}
|
var versionConfig interface{}
|
||||||
|
5
internal/flags/flags.go
Normal file
5
internal/flags/flags.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package flags
|
||||||
|
|
||||||
|
var CI bool = false
|
||||||
|
var VERBOSE bool = false
|
||||||
|
var CRON_LEAN bool = false
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
||||||
"github.com/cupcakearmy/autorestic/internal/metadata"
|
"github.com/cupcakearmy/autorestic/internal/metadata"
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
@@ -108,7 +109,7 @@ func (l Location) ExecuteHooks(commands []string, options ExecuteOptions) error
|
|||||||
colors.Error.Println(out)
|
colors.Error.Println(out)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if VERBOSE {
|
if flags.VERBOSE {
|
||||||
colors.Faint.Println(out)
|
colors.Faint.Println(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,7 +228,7 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
|||||||
options.Envs[k+"_"+fmt.Sprint(i)] = v
|
options.Envs[k+"_"+fmt.Sprint(i)] = v
|
||||||
options.Envs[k+"_"+strings.ToUpper(backend.name)] = v
|
options.Envs[k+"_"+strings.ToUpper(backend.name)] = v
|
||||||
}
|
}
|
||||||
if VERBOSE {
|
if flags.VERBOSE {
|
||||||
colors.Faint.Println(out)
|
colors.Faint.Println(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,7 +277,7 @@ func (l Location) Forget(prune bool, dry bool) error {
|
|||||||
}
|
}
|
||||||
cmd = append(cmd, combineOptions("forget", l, backend)...)
|
cmd = append(cmd, combineOptions("forget", l, backend)...)
|
||||||
out, err := ExecuteResticCommand(options, cmd...)
|
out, err := ExecuteResticCommand(options, cmd...)
|
||||||
if VERBOSE {
|
if flags.VERBOSE {
|
||||||
colors.Faint.Println(out)
|
colors.Faint.Println(out)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -367,7 +368,7 @@ func (l Location) RunCron() error {
|
|||||||
lock.SetCron(l.name, now.Unix())
|
lock.SetCron(l.name, now.Unix())
|
||||||
l.Backup(true, "")
|
l.Backup(true, "")
|
||||||
} else {
|
} else {
|
||||||
if !CRON_LEAN {
|
if !flags.CRON_LEAN {
|
||||||
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
|
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +26,9 @@ func getLock() *viper.Viper {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
file = path.Join(path.Dir(p), ".autorestic.lock.yml")
|
file = path.Join(path.Dir(p), ".autorestic.lock.yml")
|
||||||
colors.Faint.Println("Using lock:\t", file)
|
if !flags.CRON_LEAN {
|
||||||
|
colors.Faint.Println("Using lock:\t", file)
|
||||||
|
}
|
||||||
lock.SetConfigFile(file)
|
lock.SetConfigFile(file)
|
||||||
lock.SetConfigType("yml")
|
lock.SetConfigType("yml")
|
||||||
lock.ReadInConfig()
|
lock.ReadInConfig()
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||||
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RESTIC_BIN string
|
var RESTIC_BIN string
|
||||||
@@ -36,7 +37,7 @@ func ExecuteCommand(options ExecuteOptions, args ...string) (string, error) {
|
|||||||
cmd.Env = env
|
cmd.Env = env
|
||||||
cmd.Dir = options.Dir
|
cmd.Dir = options.Dir
|
||||||
|
|
||||||
if VERBOSE {
|
if flags.VERBOSE {
|
||||||
colors.Faint.Printf("> Executing: %s\n", cmd)
|
colors.Faint.Printf("> Executing: %s\n", cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user