From e074647cb42b5b80fceafc37d48348078c65533d Mon Sep 17 00:00:00 2001 From: Anisur Rahman Date: Tue, 27 Aug 2024 15:34:44 +0600 Subject: [PATCH 1/3] Add restic check cmd Signed-off-by: Anisur Rahman --- pkg/restic/check.go | 30 ++++++++++++++++++++++++++++++ pkg/restic/commands.go | 29 +++++++++++++++++++++++++++++ pkg/restic/config.go | 7 +++++++ 3 files changed, 66 insertions(+) create mode 100644 pkg/restic/check.go diff --git a/pkg/restic/check.go b/pkg/restic/check.go new file mode 100644 index 000000000..312a4deff --- /dev/null +++ b/pkg/restic/check.go @@ -0,0 +1,30 @@ +/* +Copyright AppsCode Inc. and Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package restic + +import "k8s.io/klog/v2" + +func (w *ResticWrapper) CheckRepository(opt CheckOptions) error { + params := checkParams{ + readData: opt.ReadData, + readDataSubset: opt.ReadDataSubset, + withCache: opt.WithCache, + } + out, err := w.checkRepository(params) + klog.Infoln("Output:", string(out)) + return err +} diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index fd4a83774..8c9aead32 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -76,6 +76,12 @@ type keyParams struct { file string } +type checkParams struct { + readData bool + readDataSubset string + withCache bool +} + func (w *ResticWrapper) listSnapshots(snapshotIDs []string) ([]Snapshot, error) { result := make([]Snapshot, 0) args := w.appendCacheDirFlag([]interface{}{"snapshots", "--json", "--quiet", "--no-lock"}) @@ -581,3 +587,26 @@ func (w *ResticWrapper) appendInsecureTLSFlag(args []interface{}) []interface{} } return args } + +func (w *ResticWrapper) checkRepository(params checkParams) ([]byte, error) { + klog.Infoln("Checking the repository for errors") + + args := []interface{}{"check"} + if params.readData { + args = append(args, "--read-data") + } + if params.readDataSubset != "" { + args = append(args, + fmt.Sprintf("--read-data-subset=%s", params.readDataSubset)) + } + if params.withCache { + args = append(args, "--with-cache") + } + + args = w.appendCacheDirFlag(args) + args = w.appendMaxConnectionsFlag(args) + args = w.appendCaCertFlag(args) + args = w.appendInsecureTLSFlag(args) + + return w.run(Command{Name: ResticCMD, Args: args}) +} diff --git a/pkg/restic/config.go b/pkg/restic/config.go index 11b295fab..6c154366d 100644 --- a/pkg/restic/config.go +++ b/pkg/restic/config.go @@ -101,6 +101,13 @@ type KeyOptions struct { File string } +type CheckOptions struct { + // All restic options for the 'check' command. + ReadData bool + ReadDataSubset string + WithCache bool +} + func NewResticWrapper(options SetupOptions) (*ResticWrapper, error) { wrapper := &ResticWrapper{ sh: shell.NewSession(), From fbfe2fd2a3b7c15a075de6c4ec0ffaf33052f158 Mon Sep 17 00:00:00 2001 From: Anisur Rahman Date: Tue, 27 Aug 2024 17:15:26 +0600 Subject: [PATCH 2/3] add re-build index Signed-off-by: Anisur Rahman --- pkg/restic/commands.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index 8c9aead32..f21f7ddd4 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -610,3 +610,16 @@ func (w *ResticWrapper) checkRepository(params checkParams) ([]byte, error) { return w.run(Command{Name: ResticCMD, Args: args}) } + +func (w *ResticWrapper) RebuildIndex(params []string) ([]byte, error) { + klog.Infoln("Re-building a new index for restic repository") + + args := []interface{}{"rebuild-index", params} + + args = w.appendCacheDirFlag(args) + args = w.appendMaxConnectionsFlag(args) + args = w.appendCaCertFlag(args) + args = w.appendInsecureTLSFlag(args) + + return w.run(Command{Name: ResticCMD, Args: args}) +} From 44397d7ac1d3fb580a9c392f2831a623013b7506 Mon Sep 17 00:00:00 2001 From: Anisur Rahman Date: Tue, 27 Aug 2024 18:32:53 +0600 Subject: [PATCH 3/3] make fmt linter Signed-off-by: Anisur Rahman --- pkg/restic/check.go | 30 ------------------------------ pkg/restic/commands.go | 20 ++------------------ pkg/restic/config.go | 7 ------- 3 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 pkg/restic/check.go diff --git a/pkg/restic/check.go b/pkg/restic/check.go deleted file mode 100644 index 312a4deff..000000000 --- a/pkg/restic/check.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright AppsCode Inc. and Contributors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package restic - -import "k8s.io/klog/v2" - -func (w *ResticWrapper) CheckRepository(opt CheckOptions) error { - params := checkParams{ - readData: opt.ReadData, - readDataSubset: opt.ReadDataSubset, - withCache: opt.WithCache, - } - out, err := w.checkRepository(params) - klog.Infoln("Output:", string(out)) - return err -} diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index f21f7ddd4..4a2c640aa 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -76,12 +76,6 @@ type keyParams struct { file string } -type checkParams struct { - readData bool - readDataSubset string - withCache bool -} - func (w *ResticWrapper) listSnapshots(snapshotIDs []string) ([]Snapshot, error) { result := make([]Snapshot, 0) args := w.appendCacheDirFlag([]interface{}{"snapshots", "--json", "--quiet", "--no-lock"}) @@ -588,20 +582,10 @@ func (w *ResticWrapper) appendInsecureTLSFlag(args []interface{}) []interface{} return args } -func (w *ResticWrapper) checkRepository(params checkParams) ([]byte, error) { +func (w *ResticWrapper) CheckRepository(params []string) ([]byte, error) { klog.Infoln("Checking the repository for errors") - args := []interface{}{"check"} - if params.readData { - args = append(args, "--read-data") - } - if params.readDataSubset != "" { - args = append(args, - fmt.Sprintf("--read-data-subset=%s", params.readDataSubset)) - } - if params.withCache { - args = append(args, "--with-cache") - } + args := []interface{}{"check", params} args = w.appendCacheDirFlag(args) args = w.appendMaxConnectionsFlag(args) diff --git a/pkg/restic/config.go b/pkg/restic/config.go index 6c154366d..11b295fab 100644 --- a/pkg/restic/config.go +++ b/pkg/restic/config.go @@ -101,13 +101,6 @@ type KeyOptions struct { File string } -type CheckOptions struct { - // All restic options for the 'check' command. - ReadData bool - ReadDataSubset string - WithCache bool -} - func NewResticWrapper(options SetupOptions) (*ResticWrapper, error) { wrapper := &ResticWrapper{ sh: shell.NewSession(),