mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-12-11 23:04:59 +00:00
support for volume locations
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||
@@ -114,3 +115,39 @@ func (b Backend) Exec(args []string) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (b Backend) ExecDocker(l Location, args []string) error {
|
||||
env, err := b.getEnv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
volume := l.getVolumeName()
|
||||
path, _ := l.getPath()
|
||||
options := ExecuteOptions{
|
||||
Command: "docker",
|
||||
Envs: env,
|
||||
}
|
||||
docker := []string{
|
||||
"run", "--rm",
|
||||
"--entrypoint", "ash",
|
||||
"--workdir", path,
|
||||
"--volume", volume + ":" + path,
|
||||
}
|
||||
if hostname, err := os.Hostname(); err == nil {
|
||||
docker = append(docker, "--hostname", hostname)
|
||||
}
|
||||
if b.Type == "local" {
|
||||
actual := env["RESTIC_REPOSITORY"]
|
||||
docker = append(docker, "--volume", actual+":"+"/repo")
|
||||
env["RESTIC_REPOSITORY"] = "/repo"
|
||||
}
|
||||
for key, value := range env {
|
||||
docker = append(docker, "--env", key+"="+value)
|
||||
}
|
||||
docker = append(docker, "restic/restic", "-c", "restic "+strings.Join(args, " "))
|
||||
out, err := ExecuteCommand(options, docker...)
|
||||
if VERBOSE {
|
||||
colors.Faint.Println(out)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user