Skip to content

Commit 1d06cd4

Browse files
dotborisbishtawi
authored andcommitted
feat: Allow lockfile path to be configured
1 parent 9cf919b commit 1d06cd4

17 files changed

Lines changed: 153 additions & 55 deletions

File tree

cmd/backup.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/cupcakearmy/autorestic/internal"
88
"github.com/cupcakearmy/autorestic/internal/colors"
9-
"github.com/cupcakearmy/autorestic/internal/lock"
109
"github.com/spf13/cobra"
1110
)
1211

@@ -15,9 +14,9 @@ var backupCmd = &cobra.Command{
1514
Short: "Create backups for given locations",
1615
Run: func(cmd *cobra.Command, args []string) {
1716
internal.GetConfig()
18-
err := lock.Lock()
17+
err := internal.Lock()
1918
CheckErr(err)
20-
defer lock.Unlock()
19+
defer internal.Unlock()
2120
dry, _ := cmd.Flags().GetBool("dry-run")
2221

2322
selected, err := internal.GetAllOrSelected(cmd, false)

cmd/check.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"github.com/cupcakearmy/autorestic/internal"
55
"github.com/cupcakearmy/autorestic/internal/colors"
6-
"github.com/cupcakearmy/autorestic/internal/lock"
76
"github.com/spf13/cobra"
87
)
98

@@ -12,9 +11,9 @@ var checkCmd = &cobra.Command{
1211
Short: "Check if everything is setup",
1312
Run: func(cmd *cobra.Command, args []string) {
1413
internal.GetConfig()
15-
err := lock.Lock()
14+
err := internal.Lock()
1615
CheckErr(err)
17-
defer lock.Unlock()
16+
defer internal.Unlock()
1817

1918
CheckErr(internal.CheckConfig())
2019

cmd/cron.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"github.com/cupcakearmy/autorestic/internal"
55
"github.com/cupcakearmy/autorestic/internal/flags"
6-
"github.com/cupcakearmy/autorestic/internal/lock"
76
"github.com/spf13/cobra"
87
)
98

@@ -13,9 +12,9 @@ var cronCmd = &cobra.Command{
1312
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.`,
1413
Run: func(cmd *cobra.Command, args []string) {
1514
internal.GetConfig()
16-
err := lock.Lock()
15+
err := internal.Lock()
1716
CheckErr(err)
18-
defer lock.Unlock()
17+
defer internal.Unlock()
1918

2019
err = internal.RunCron()
2120
CheckErr(err)

cmd/exec.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/cupcakearmy/autorestic/internal"
77
"github.com/cupcakearmy/autorestic/internal/colors"
8-
"github.com/cupcakearmy/autorestic/internal/lock"
98
"github.com/spf13/cobra"
109
)
1110

@@ -14,9 +13,9 @@ var execCmd = &cobra.Command{
1413
Short: "Execute arbitrary native restic commands for given backends",
1514
Run: func(cmd *cobra.Command, args []string) {
1615
internal.GetConfig()
17-
err := lock.Lock()
16+
err := internal.Lock()
1817
CheckErr(err)
19-
defer lock.Unlock()
18+
defer internal.Unlock()
2019

2120
selected, err := internal.GetAllOrSelected(cmd, true)
2221
CheckErr(err)

cmd/forget.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"github.com/cupcakearmy/autorestic/internal"
5-
"github.com/cupcakearmy/autorestic/internal/lock"
65
"github.com/spf13/cobra"
76
)
87

@@ -11,9 +10,9 @@ var forgetCmd = &cobra.Command{
1110
Short: "Forget and optionally prune snapshots according the specified policies",
1211
Run: func(cmd *cobra.Command, args []string) {
1312
internal.GetConfig()
14-
err := lock.Lock()
13+
err := internal.Lock()
1514
CheckErr(err)
16-
defer lock.Unlock()
15+
defer internal.Unlock()
1716

1817
selected, err := internal.GetAllOrSelected(cmd, false)
1918
CheckErr(err)

cmd/restore.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/cupcakearmy/autorestic/internal"
7-
"github.com/cupcakearmy/autorestic/internal/lock"
87
"github.com/spf13/cobra"
98
)
109

@@ -14,9 +13,9 @@ var restoreCmd = &cobra.Command{
1413
Args: cobra.MaximumNArgs(1),
1514
Run: func(cmd *cobra.Command, args []string) {
1615
internal.GetConfig()
17-
err := lock.Lock()
16+
err := internal.Lock()
1817
CheckErr(err)
19-
defer lock.Unlock()
18+
defer internal.Unlock()
2019

2120
location, _ := cmd.Flags().GetString("location")
2221
l, ok := internal.GetLocation(location)

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/cupcakearmy/autorestic/internal"
99
"github.com/cupcakearmy/autorestic/internal/colors"
1010
"github.com/cupcakearmy/autorestic/internal/flags"
11-
"github.com/cupcakearmy/autorestic/internal/lock"
1211
"github.com/spf13/cobra"
1312

1413
homedir "github.com/mitchellh/go-homedir"
@@ -18,7 +17,7 @@ import (
1817
func CheckErr(err error) {
1918
if err != nil {
2019
colors.Error.Fprintln(os.Stderr, "Error:", err)
21-
lock.Unlock()
20+
internal.Unlock()
2221
os.Exit(1)
2322
}
2423
}
@@ -42,6 +41,7 @@ func init() {
4241
rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode")
4342
rootCmd.PersistentFlags().StringVar(&flags.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
4443
rootCmd.PersistentFlags().StringVar(&flags.DOCKER_IMAGE, "docker-image", "cupcakearmy/autorestic:"+internal.VERSION, "specify a custom docker image")
44+
rootCmd.PersistentFlags().StringVar(&flags.LOCKFILE, "lockfile", "", "specify a custom path for the lockfile (defaults to .autorestic.lock.yml next to the loaded autorestic config file)")
4545
cobra.OnInitialize(initConfig)
4646
}
4747

cmd/unlock.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/cupcakearmy/autorestic/internal"
1111
"github.com/cupcakearmy/autorestic/internal/colors"
12-
"github.com/cupcakearmy/autorestic/internal/lock"
1312
"github.com/spf13/cobra"
1413
)
1514

@@ -33,7 +32,7 @@ To check you can run "ps aux | grep autorestic".`,
3332
}
3433
}
3534

36-
err := lock.Unlock()
35+
err := internal.Unlock()
3736
if err != nil {
3837
colors.Error.Println("Could not unlock:", err)
3938
return

docs/pages/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"quick": "Quick Start",
44
"installation": "Installation",
55
"config": "Configuration",
6+
"lockfile": "Lockfile",
67
"location": "Locations",
78
"backend": "Backend",
89
"cli": "CLI",

docs/pages/cli/general.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ With `--restic-bin` you can specify to run a specific restic binary. This can be
3434
```bash
3535
autorestic --restic-bin /some/path/to/my/custom/restic/binary
3636
```
37+
38+
## `--lockfile`
39+
40+
Specify the path for the [lockfile](../lockfile.md) used by `autorestic`. If omitted, this will default to `.autorestic.lock.yml` next to the loaded config file.
41+
42+
```bash
43+
autorestic --lockfile /path/to/my/.autorestic.lock.yml
44+
```

0 commit comments

Comments
 (0)