Skip to content

Commit

Permalink
support for custom_flags in repositories in addition to backups
Browse files Browse the repository at this point in the history
  • Loading branch information
fgma committed May 1, 2020
1 parent 04fcd76 commit 1bce144
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ check
read_data_percentage
An integer value between 0 and 100. Specifies the percentage of randomly choosen data in the repository that is checked for modifications on each run of check. If 100% is not an integer multiple of the given percentage the given percentage will be adjusted accordingly. E.g. a percentage of 50% will check half of the repository on each check while a percentage of 43% will only check 33% of the repository on each check.

custom_flags
String array of custom flags that are not directly supported e.g. ``--ignore-inode``. All flags are directly passed to restic. Unsupported flags might break restic backups.

handler
Handlers are called at specific events during execution. They may be used to run custom scripts e.g. to notify the user about a successful check of the repository.

Expand Down
2 changes: 1 addition & 1 deletion cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var shellCmd = &cobra.Command{
os.Exit(1)
}

c := restic.PrepareResticEnvironmentCommand(shell, repository.URL, repository.Password, repository.Environment, 0, 0)
c := restic.PrepareResticEnvironmentCommand(shell, repository.URL, repository.Password, repository.Environment, 0, 0, []string{})
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ var versionCmd = &cobra.Command{
Short: "Print the version number",
Long: `Print the version number"`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("rester v0.1.1 -- " + versionRevision)
fmt.Println("rester v0.1.2 -- " + versionRevision)
},
}
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
rester (0.1.2-1) unstable; urgency=medium

* Update to 0.1.2.

-- root <root@localhost> Thu, 3 Dec 2018 20:00:00 +0000


rester (0.1.1-1) unstable; urgency=medium

* Initial release.
Expand Down
1 change: 1 addition & 0 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Repository struct {
Password string `json:"password,omitempty"`
Environment map[string]string `json:"environment,omitempty"`
Check Check `json:"check,omitempty"`
CustomFlags []string `json:"custom_flags,omitempty"`
repositoryDefaultable
}

Expand Down
6 changes: 5 additions & 1 deletion internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func TestLoadConfig(t *testing.T) {
},
"check": {
"read_data_percentage": 5
}
},
"custom_flags": [ "-o", "key=value" ]
}
],
"backups": [
Expand Down Expand Up @@ -87,6 +88,9 @@ func TestLoadConfig(t *testing.T) {
assert.Equal(t, "/home/test/repos/test2", config.Repositories[1].URL)
assert.Equal(t, "2", config.Repositories[1].Password)
assert.Equal(t, uint(5), config.Repositories[1].Check.ReadDataPercentage)
assert.Equal(t, 2, len(config.Repositories[1].CustomFlags), "invalid custom flag")
assert.Equal(t, "-o", config.Repositories[1].CustomFlags[0])
assert.Equal(t, "key=value", config.Repositories[1].CustomFlags[1])
assert.Equal(t, "notify_send -t 1000 check done", config.Repositories[1].Handler.CheckSuccess)
assert.Equal(t, "notify_send check failed", config.Repositories[1].Handler.CheckFailure)
assert.Equal(t, "notify_send -t 1000 forget done", config.Repositories[1].Handler.ForgetSuccess)
Expand Down
8 changes: 6 additions & 2 deletions internal/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,13 @@ func (r Restic) prepareResticCommand(
environment := combineMaps(repo.Environment, additionalEnvironment)
return r.PrepareResticEnvironmentCommand(
r.resticExecutable, repo.URL, repo.Password, environment,
repo.LimitDownload, repo.LimitUpload,
repo.LimitDownload, repo.LimitUpload, repo.CustomFlags,
)
}

func (r Restic) PrepareResticEnvironmentCommand(
command string, repoURL string, password string, environment map[string]string,
limitDownload int, limitUpload int,
limitDownload int, limitUpload int, customFlags []string,
) *exec.Cmd {
cmd := exec.Command(command)

Expand All @@ -478,6 +478,10 @@ func (r Restic) PrepareResticEnvironmentCommand(
cmd.Args = append(cmd.Args, "--limit-upload", strconv.Itoa(limitUpload))
}

for _, flag := range customFlags {
cmd.Args = append(cmd.Args, flag)
}

cmd.Env = append(
os.Environ(),
convertEnvironment(environment)...,
Expand Down

0 comments on commit 1bce144

Please sign in to comment.