From 389f7c25dd3ddd8a530eaa61ef7c333fb4e5d6cf Mon Sep 17 00:00:00 2001 From: Gavin Chappell <2798739+g-a-c@users.noreply.github.com> Date: Sat, 20 Nov 2021 19:30:46 +0000 Subject: [PATCH 01/11] refactor downloading of binaries * If `/tmp` is a `tmpfs` or somehow not the same filesystem, `os.Rename()` will fail so use `io.Copy()` instead * don't defer cleanup of `to` as this removes the newly-created file if the operation is successful, making `install` and `upgrade` _functionally_ `uninstall` * defer cleanup of the temporary file since it will still be in place if `os.Rename()` fails Fixes: #130 --- internal/bins/bins.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/bins/bins.go b/internal/bins/bins.go index 27c640c..2d90667 100644 --- a/internal/bins/bins.go +++ b/internal/bins/bins.go @@ -87,9 +87,23 @@ func downloadAndInstallAsset(body GithubRelease, name string) error { } to := path.Join(INSTALL_PATH, name) - defer os.Remove(to) // Delete if current, ignore error if file does not exits. + defer os.Remove(tmp.Name()) // Cleanup temporary file after thread exits if err := os.Rename(tmp.Name(), to); err != nil { - return nil + colors.Error.Printf("os.Rename() failed (%v), retrying with io.Copy()\n", err.Error()) + var src *os.File + var dst *os.File + if src, err = os.Open(tmp.Name()); err != nil { + return err + } + if dst, err = os.Create(to); err != nil { + return err + } + if _, err := io.Copy(dst, src); err != nil { + return err + } + if err := os.Chmod(to, 0755); err != nil { + return err + } } colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH) From 0c71bea93ee92a2cc474de9252abf07f8b573159 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sun, 21 Nov 2021 21:10:32 +0100 Subject: [PATCH 02/11] use own docker image --- CHANGELOG.md | 6 ++++++ internal/backend.go | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5d899..1fac099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.5.1] - 2021-11-21 + +### Changed + +- use official docker image instead of installing rclone every time docker is used. + ## [1.5.0] - 2021-11-20 ### Added diff --git a/internal/backend.go b/internal/backend.go index 0eb8773..089b48c 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -194,15 +194,13 @@ func (b Backend) ExecDocker(l Location, args []string) (string, error) { splitted := strings.Split(strings.TrimSpace(configFile), "\n") configFilePath := splitted[len(splitted)-1] docker = append(docker, "--volume", configFilePath+":"+"/root/.config/rclone/rclone.conf:ro") - // Install rclone in the container - args = append([]string{"apk", "add", "rclone", "&&"}, args...) default: return "", fmt.Errorf("Backend type \"%s\" is not supported as volume endpoint", b.Type) } for key, value := range env { docker = append(docker, "--env", key+"="+value) } - docker = append(docker, "restic/restic", "-c", strings.Join(args, " ")) + docker = append(docker, "cupcakearmy/autorestic", "-c", strings.Join(args, " ")) out, err := ExecuteCommand(options, docker...) return out, err } From 26de4385ea3cd3fd04f3d3172e3b096abe8c8c82 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Tue, 23 Nov 2021 12:32:22 +0100 Subject: [PATCH 03/11] version bump --- internal/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config.go b/internal/config.go index 9d5c253..5909df8 100644 --- a/internal/config.go +++ b/internal/config.go @@ -16,7 +16,7 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.5.0" +const VERSION = "1.5.1" var CI bool = false var VERBOSE bool = false From 252968e15e0272b2b8c9d7f28501e3016dc9d131 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Tue, 23 Nov 2021 12:32:35 +0100 Subject: [PATCH 04/11] ensure config is loaded before lock --- CHANGELOG.md | 60 +++++++++++++++++++++++-------------------- cmd/check.go | 1 + cmd/cron.go | 1 + cmd/restore.go | 1 + internal/lock/lock.go | 10 ++++++-- 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fac099..6563732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,23 +11,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - use official docker image instead of installing rclone every time docker is used. +### Fixed + +- lock file not always next to the config file. + ## [1.5.0] - 2021-11-20 ### Added -- Support for multiple paths -- Improved error handling -- Allow for specific snapshot to be restored -- Docker image +- Support for multiple paths. +- Improved error handling. +- Allow for specific snapshot to be restored. +- Docker image. ### Fixed -- rclone in docker volumes +- rclone in docker volumes. ### Changed -- [Breaking Change] Declaration of docker volumes. See: https://autorestic.vercel.app/migration/1.4_1.5 -- [Breaking Change] Hooks default executing directory now defaults to the config file directory. See: https://autorestic.vercel.app/migration/1.4_1.5 +- [Breaking Change] Declaration of docker volumes. See: https://autorestic.vercel.app/migration/1.4_1.5. +- [Breaking Change] Hooks default executing directory now defaults to the config file directory. See: https://autorestic.vercel.app/migration/1.4_1.5. ## [1.4.1] - 2021-10-31 @@ -39,26 +43,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Allow specify to specify a backend for location backup -- Global restic flags -- Generic ENV support for backends +- Allow specify to specify a backend for location backup. +- Global restic flags. +- Generic ENV support for backends. ### Changed -- Install now only requires `wget` -- Env variable for the `KEY` has been renamed from `AUTORESTIC_[BACKEND NAME]_KEY` -> `AUTORESTIC_[BACKEND NAME]_RESTIC_PASSWORD` +- Install now only requires `wget`. +- Env variable for the `KEY` has been renamed from `AUTORESTIC_[BACKEND NAME]_KEY` -> `AUTORESTIC_[BACKEND NAME]_RESTIC_PASSWORD`. ### Fixed -- Error handling during upgrade & uninstall +- Error handling during upgrade & uninstall. ## [1.3.0] - 2021-10-26 ### Added -- Pass restic backup metadata as ENV to hooks +- Pass restic backup metadata as ENV to hooks. - Support for `XDG_CONFIG_HOME` and `${HOME}/.config` as default locations for `.autorestic.yaml` file. -- Binary restic flags are now supported +- Binary restic flags are now supported. - Pass encryption keys from env variables or files. ## [1.2.0] - 2021-08-05 @@ -66,12 +70,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Community page -- Support for yaml references and aliases +- Support for yaml references and aliases. ### Fixed -- Better verbose output for hooks -- Better error message for bad formatted configs +- Better verbose output for hooks. +- Better error message for bad formatted configs. ## [1.1.2] - 2021-07-11 @@ -83,24 +87,24 @@ Don't check all backend when running `forget` or `exec` commands. ### Added -- Options for backends +- Options for backends. ## [1.1.0] - 2021-05-06 ### Added -- use custom restic binary -- success & failure hooks +- use custom restic binary. +- success & failure hooks. ### Fixed -- don't skip other locations on failure +- don't skip other locations on failure. ## [1.0.9] - 2021-05-01 ### Fixed -- Validation for docker volumes +- Validation for docker volumes. ## [1.0.8] - 2021-04-28 @@ -123,7 +127,7 @@ Don't check all backend when running `forget` or `exec` commands. ### Added -- Support for rclone +- Support for rclone. ## [1.0.5] - 2021-04-24 @@ -136,17 +140,17 @@ Don't check all backend when running `forget` or `exec` commands. ### Added -- Options to add rest username and password in config +- Options to add rest username and password in config. ### Fixed -- Don't add empty strings when saving config +- Don't add empty strings when saving config. ## [1.0.3] - 2021-04-20 ### Fixed -- Auto upgrade script was not working on linux as linux does not support writing to the binary that is being executed +- Auto upgrade script was not working on linux as linux does not support writing to the binary that is being executed. ## [1.0.2] - 2021-04-20 @@ -162,7 +166,7 @@ Don't check all backend when running `forget` or `exec` commands. ### Added -- Completion command for various shells +- Completion command for various shells. ## [1.0.0] - 2021-04-17 diff --git a/cmd/check.go b/cmd/check.go index 2ff9485..159f341 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -11,6 +11,7 @@ var checkCmd = &cobra.Command{ Use: "check", Short: "Check if everything is setup", Run: func(cmd *cobra.Command, args []string) { + internal.GetConfig() err := lock.Lock() CheckErr(err) defer lock.Unlock() diff --git a/cmd/cron.go b/cmd/cron.go index 2f80bf7..5ea0c7f 100644 --- a/cmd/cron.go +++ b/cmd/cron.go @@ -11,6 +11,7 @@ var cronCmd = &cobra.Command{ Short: "Run cron job for automated backups", 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) { + internal.GetConfig() internal.CRON_LEAN, _ = cmd.Flags().GetBool("lean") err := lock.Lock() CheckErr(err) diff --git a/cmd/restore.go b/cmd/restore.go index f22a1dd..38df5e0 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -13,6 +13,7 @@ var restoreCmd = &cobra.Command{ Short: "Restore backup for location", Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { + internal.GetConfig() err := lock.Lock() CheckErr(err) defer lock.Unlock() diff --git a/internal/lock/lock.go b/internal/lock/lock.go index 0265142..4cae533 100644 --- a/internal/lock/lock.go +++ b/internal/lock/lock.go @@ -19,8 +19,14 @@ func getLock() *viper.Viper { once.Do(func() { lock = viper.New() lock.SetDefault("running", false) - p := path.Dir(viper.ConfigFileUsed()) - file = path.Join(p, ".autorestic.lock.yml") + p := viper.ConfigFileUsed() + colors.Primary.Println(p) + if p == "" { + colors.Error.Println("cannot lock before reading config location") + os.Exit(1) + } + file = path.Join(path.Dir(p), ".autorestic.lock.yml") + colors.Faint.Println("Using lock:\t", file) lock.SetConfigFile(file) lock.SetConfigType("yml") lock.ReadInConfig() From 2b14e6b1af5ddea396082a29966cb5c2bb6b3112 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 24 Nov 2021 09:35:31 +0100 Subject: [PATCH 05/11] remove print --- internal/lock/lock.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/lock/lock.go b/internal/lock/lock.go index 4cae533..b07727b 100644 --- a/internal/lock/lock.go +++ b/internal/lock/lock.go @@ -20,7 +20,6 @@ func getLock() *viper.Viper { lock = viper.New() lock.SetDefault("running", false) p := viper.ConfigFileUsed() - colors.Primary.Println(p) if p == "" { colors.Error.Println("cannot lock before reading config location") os.Exit(1) From e0b2c99ccd3dd7026c4cfbc827d05a1a0f50946b Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 24 Nov 2021 09:45:19 +0100 Subject: [PATCH 06/11] contrib --- docs/markdown/contrib.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/markdown/contrib.md b/docs/markdown/contrib.md index aa1043d..e159051 100644 --- a/docs/markdown/contrib.md +++ b/docs/markdown/contrib.md @@ -3,6 +3,7 @@ This amazing people helped the project! - @agateblue - Docs, Pruning, S3 +- @g-a-c - Update/Install bugs. - @david-boles - Docs - @SebDanielsson - Brew - @n194 - AUR Package From 3b541665ae240b534de58595e69389536ce45dcc Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 24 Nov 2021 09:45:23 +0100 Subject: [PATCH 07/11] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6563732..4c16274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - lock file not always next to the config file. +- update / install bugs. ## [1.5.0] - 2021-11-20 From e3c378f2a1c01cd8902bdebb676c8e1a63fcd6d3 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 24 Nov 2021 09:57:10 +0100 Subject: [PATCH 08/11] release day --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c16274..182df9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ 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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.5.1] - 2021-11-21 +## [1.5.1] - 2021-11-24 ### Changed From 0c37af5588c5c1273c84807de3f9806be0abc336 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Mon, 6 Dec 2021 11:59:58 +0100 Subject: [PATCH 09/11] #140 Docker version pinning --- internal/backend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/backend.go b/internal/backend.go index 089b48c..69cd5f8 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -200,7 +200,7 @@ func (b Backend) ExecDocker(l Location, args []string) (string, error) { for key, value := range env { docker = append(docker, "--env", key+"="+value) } - docker = append(docker, "cupcakearmy/autorestic", "-c", strings.Join(args, " ")) + docker = append(docker, "cupcakearmy/autorestic:"+VERSION, "-c", strings.Join(args, " ")) out, err := ExecuteCommand(options, docker...) return out, err } From 982f9e0b5cc1c77b918b959879f0a0f83c9793ab Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Mon, 6 Dec 2021 12:13:18 +0100 Subject: [PATCH 10/11] better error handling --- cmd/backup.go | 2 +- internal/location.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/backup.go b/cmd/backup.go index 38d3fe1..a575220 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -31,7 +31,7 @@ var backupCmd = &cobra.Command{ location, _ := internal.GetLocation(splitted[0]) errs := location.Backup(false, specificBackend) for _, err := range errs { - colors.Error.Println(err) + colors.Error.Printf("%s\n\n", err) errors++ } } diff --git a/internal/location.go b/internal/location.go index 2b2e4a3..b94b916 100644 --- a/internal/location.go +++ b/internal/location.go @@ -216,7 +216,8 @@ func (l Location) Backup(cron bool, specificBackend string) []error { out, err = backend.ExecDocker(l, cmd) } if err != nil { - errors = append(errors, err) + colors.Error.Println(out) + errors = append(errors, fmt.Errorf("%s@%s:\n%s%s", l.name, backend.name, out, err)) continue } From 21b83b4c89abecc18463e36e9b46743f5891873e Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Mon, 6 Dec 2021 17:20:06 +0100 Subject: [PATCH 11/11] docker docs --- docs/markdown/_toc.md | 1 + docs/markdown/docker.md | 28 ++++++++++++++++++++++++++++ docs/markdown/installation.md | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 docs/markdown/docker.md diff --git a/docs/markdown/_toc.md b/docs/markdown/_toc.md index bd4e321..9024e0c 100644 --- a/docs/markdown/_toc.md +++ b/docs/markdown/_toc.md @@ -46,6 +46,7 @@ > [1.4 → 1.5](/migration/1.4_1.5) [Examples](/examples) +[Docker](/docker) [QA](/qa) [Community](/community) [Contributors](/contrib) diff --git a/docs/markdown/docker.md b/docs/markdown/docker.md new file mode 100644 index 0000000..32636d2 --- /dev/null +++ b/docs/markdown/docker.md @@ -0,0 +1,28 @@ +# 🐳 Docker + +The docker image is build with rclone and restic already included. It's ment more as a utility image. + +## Remote hosts + +For remote backups (S3, B2, GCS, etc.) it's quite easy, as you only need to mount the config file and the data to backup. + +```bash +docker run --rm \\ + -v $(pwd):/data \\ + cupcakearmy/autorestic \\ + autorestic backup -va +``` + +## Rclone + +For rclone you will have to also mount the rclone config file to `/root/.config/rclone/rclone.conf`. + +To check where it is located you can run the following command: `rclone config file`. + +**Example** + +```bash +docker run \\ + -v /home/user/.config/rclone/rclone.conf:/root/.config/rclone/rclone.conf:ro \\ + ... +``` diff --git a/docs/markdown/installation.md b/docs/markdown/installation.md index 071e9c5..e932d44 100644 --- a/docs/markdown/installation.md +++ b/docs/markdown/installation.md @@ -14,6 +14,8 @@ wget -qO - https://raw.githubusercontent.com/CupCakeArmy/autorestic/master/insta There is an official docker image over at [cupcakearmy/autorestic](https://hub.docker.com/r/cupcakearmy/autorestic). +For some examples see [here](/docker). + ### Manual You can download the right binary from the release page and simply copy it to `/usr/local/bin` or whatever path you prefer. Autoupdates will still work.