Compare commits

...

4 Commits

Author SHA1 Message Date
fliespl
076779c848
Merge d332f4476b into 8a773856de 2024-10-21 16:07:41 +02:00
Wez Furlong
8a773856de
Improve error handling in install.sh (#404)
Prior to this change, running the example from the docs without root privs produces this misleading/confusing output that claims that the software was installed when it wasn't:

```console
$ wget -qO - https://raw.githubusercontent.com/cupcakearmy/autorestic/master/install.sh | bash
linux
amd64
/usr/local/bin/autorestic.bz2: Permission denied
bzip2: Can't open input file /usr/local/bin/autorestic.bz2: No such file or directory.
chmod: cannot access '/usr/local/bin/autorestic': No such file or directory
bash: line 49: autorestic: command not found
Successfully installed autorestic
```

With this change, the errors stop the script much earlier and produce this output instead:

```
linux
amd64
/usr/local/bin/autorestic.bz2: Permission denied
```
2024-10-21 16:06:49 +02:00
Boris Bera
41e4e4a5f3
fix(cron): crash when errors are encountered during a backup (#403) 2024-10-17 13:49:45 +02:00
fliespl
d332f4476b
do not replace all shell paths in the example 2023-10-24 22:10:41 +02:00
4 changed files with 18 additions and 4 deletions

View File

@ -34,7 +34,7 @@ Then paste this at the bottom of the file and save it. Note that in this specifi
```bash ```bash
# This is required, as it otherwise cannot find restic as a command. # This is required, as it otherwise cannot find restic as a command.
PATH="/usr/local/bin:/usr/bin:/bin" PATH="/usr/local/bin:$PATH"
# Example running every 5 minutes # Example running every 5 minutes
*/5 * * * * autorestic -c /path/to/my/.autorestic.yml --ci cron */5 * * * * autorestic -c /path/to/my/.autorestic.yml --ci cron

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
set -e -o pipefail
shopt -s nocaseglob shopt -s nocaseglob
OUT_FILE=/usr/local/bin/autorestic OUT_FILE=/usr/local/bin/autorestic

View File

@ -1,12 +1,22 @@
package internal package internal
import (
"errors"
"fmt"
)
func RunCron() error { func RunCron() error {
c := GetConfig() c := GetConfig()
var errs []error
for name, l := range c.Locations { for name, l := range c.Locations {
l.name = name l.name = name
if err := l.RunCron(); err != nil { if err := l.RunCron(); err != nil {
return err errs = append(errs, err)
} }
} }
if len(errs) > 0 {
return fmt.Errorf("Encountered errors during cron process:\n%w", errors.Join(errs...))
}
return nil return nil
} }

View File

@ -1,6 +1,7 @@
package internal package internal
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -446,7 +447,10 @@ func (l Location) RunCron() error {
now := time.Now() now := time.Now()
if now.After(next) { if now.After(next) {
lock.SetCron(l.name, now.Unix()) lock.SetCron(l.name, now.Unix())
l.Backup(true, "") errs := l.Backup(true, "")
if len(errs) > 0 {
return fmt.Errorf("Failed to backup location \"%s\":\n%w", l.name, errors.Join(errs...))
}
} else { } else {
if !flags.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)