mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-07 11:00:39 +00:00
fixes
This commit is contained in:
@@ -25,7 +25,7 @@ func GetBackend(name string) (Backend, bool) {
|
||||
func (b Backend) generateRepo() (string, error) {
|
||||
switch b.Type {
|
||||
case "local":
|
||||
return GetPathRelativeToConfig(b.Path), nil
|
||||
return GetPathRelativeToConfig(b.Path)
|
||||
case "b2", "azure", "gs", "s3", "sftp", "rest":
|
||||
return fmt.Sprintf("%s:%s", b.Type, b.Path), nil
|
||||
default:
|
||||
@@ -33,21 +33,22 @@ func (b Backend) generateRepo() (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b Backend) getEnv() map[string]string {
|
||||
func (b Backend) getEnv() (map[string]string, error) {
|
||||
env := make(map[string]string)
|
||||
env["RESTIC_PASSWORD"] = b.Key
|
||||
repo, err := b.generateRepo()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
env["RESTIC_REPOSITORY"] = repo
|
||||
return env
|
||||
return env, err
|
||||
}
|
||||
|
||||
func (b Backend) validate() error {
|
||||
options := ExecuteOptions{Envs: b.getEnv()}
|
||||
env, err := b.getEnv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
options := ExecuteOptions{Envs: env}
|
||||
// Check if already initialized
|
||||
_, err := ExecuteResticCommand(options, "snapshots")
|
||||
_, err = ExecuteResticCommand(options, "snapshots")
|
||||
if err == nil {
|
||||
return nil
|
||||
} else {
|
||||
@@ -59,7 +60,11 @@ func (b Backend) validate() error {
|
||||
}
|
||||
|
||||
func (b Backend) Exec(args []string) error {
|
||||
options := ExecuteOptions{Envs: b.getEnv()}
|
||||
env, err := b.getEnv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
options := ExecuteOptions{Envs: env}
|
||||
out, err := ExecuteResticCommand(options, args...)
|
||||
fmt.Println(out)
|
||||
return err
|
||||
|
Reference in New Issue
Block a user