|
|
@ -12,6 +12,8 @@ import (
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/flags"
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/metadata"
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/metadata"
|
|
|
|
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/utils"
|
|
|
|
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/options"
|
|
|
|
"github.com/robfig/cron"
|
|
|
|
"github.com/robfig/cron"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +51,7 @@ type Location struct {
|
|
|
|
To []string `mapstructure:"to,omitempty"`
|
|
|
|
To []string `mapstructure:"to,omitempty"`
|
|
|
|
Hooks Hooks `mapstructure:"hooks,omitempty"`
|
|
|
|
Hooks Hooks `mapstructure:"hooks,omitempty"`
|
|
|
|
Cron string `mapstructure:"cron,omitempty"`
|
|
|
|
Cron string `mapstructure:"cron,omitempty"`
|
|
|
|
Options Options `mapstructure:"options,omitempty"`
|
|
|
|
Options options.Options `mapstructure:"options,omitempty"`
|
|
|
|
ForgetOption LocationForgetOption `mapstructure:"forget,omitempty"`
|
|
|
|
ForgetOption LocationForgetOption `mapstructure:"forget,omitempty"`
|
|
|
|
CopyOption LocationCopy `mapstructure:"copy,omitempty"`
|
|
|
|
CopyOption LocationCopy `mapstructure:"copy,omitempty"`
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,14 +103,14 @@ func (l Location) validate() error {
|
|
|
|
if _, ok := GetBackend(copyFrom); !ok {
|
|
|
|
if _, ok := GetBackend(copyFrom); !ok {
|
|
|
|
return fmt.Errorf(`location "%s" has an invalid backend "%s" in copy option`, l.name, copyFrom)
|
|
|
|
return fmt.Errorf(`location "%s" has an invalid backend "%s" in copy option`, l.name, copyFrom)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !ArrayContains(l.To, copyFrom) {
|
|
|
|
if !utils.ArrayContains(l.To, copyFrom) {
|
|
|
|
return fmt.Errorf(`location "%s" has an invalid copy from "%s"`, l.name, copyFrom)
|
|
|
|
return fmt.Errorf(`location "%s" has an invalid copy from "%s"`, l.name, copyFrom)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, copyToTarget := range copyTo {
|
|
|
|
for _, copyToTarget := range copyTo {
|
|
|
|
if _, ok := GetBackend(copyToTarget); !ok {
|
|
|
|
if _, ok := GetBackend(copyToTarget); !ok {
|
|
|
|
return fmt.Errorf(`location "%s" has an invalid backend "%s" in copy option`, l.name, copyToTarget)
|
|
|
|
return fmt.Errorf(`location "%s" has an invalid backend "%s" in copy option`, l.name, copyToTarget)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ArrayContains(l.To, copyToTarget) {
|
|
|
|
if utils.ArrayContains(l.To, copyToTarget) {
|
|
|
|
return fmt.Errorf(`location "%s" cannot copy to "%s" as it's already a target`, l.name, copyToTarget)
|
|
|
|
return fmt.Errorf(`location "%s" cannot copy to "%s" as it's already a target`, l.name, copyToTarget)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -123,7 +125,7 @@ func (l Location) validate() error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l Location) ExecuteHooks(commands []string, options ExecuteOptions) error {
|
|
|
|
func (l Location) ExecuteHooks(commands []string, options utils.ExecuteOptions) error {
|
|
|
|
if len(commands) == 0 {
|
|
|
|
if len(commands) == 0 {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -137,7 +139,7 @@ func (l Location) ExecuteHooks(commands []string, options ExecuteOptions) error
|
|
|
|
colors.Secondary.Println("\nRunning hooks")
|
|
|
|
colors.Secondary.Println("\nRunning hooks")
|
|
|
|
for _, command := range commands {
|
|
|
|
for _, command := range commands {
|
|
|
|
colors.Body.Println("> " + command)
|
|
|
|
colors.Body.Println("> " + command)
|
|
|
|
_, out, err := ExecuteCommand(options, "-c", command)
|
|
|
|
_, out, err := utils.ExecuteCommand(options, "-c", command)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
colors.Error.Println(out)
|
|
|
|
colors.Error.Println(out)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -176,7 +178,7 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
|
|
|
return errors
|
|
|
|
return errors
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cwd, _ := GetPathRelativeToConfig(".")
|
|
|
|
cwd, _ := GetPathRelativeToConfig(".")
|
|
|
|
options := ExecuteOptions{
|
|
|
|
options := utils.ExecuteOptions{
|
|
|
|
Command: "bash",
|
|
|
|
Command: "bash",
|
|
|
|
Dir: cwd,
|
|
|
|
Dir: cwd,
|
|
|
|
Envs: map[string]string{
|
|
|
|
Envs: map[string]string{
|
|
|
@ -221,8 +223,9 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
|
|
|
cmd = append(cmd, "--tag", buildTag("cron"))
|
|
|
|
cmd = append(cmd, "--tag", buildTag("cron"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd = append(cmd, "--tag", l.getLocationTags())
|
|
|
|
cmd = append(cmd, "--tag", l.getLocationTags())
|
|
|
|
backupOptions := ExecuteOptions{
|
|
|
|
backupOptions := utils.ExecuteOptions{
|
|
|
|
Envs: env,
|
|
|
|
Envs: env,
|
|
|
|
|
|
|
|
Global: GetConfig().Global,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var code int = 0
|
|
|
|
var code int = 0
|
|
|
@ -237,9 +240,9 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd = append(cmd, path)
|
|
|
|
cmd = append(cmd, path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
code, out, err = ExecuteResticCommand(backupOptions, cmd...)
|
|
|
|
code, out, err = utils.ExecuteResticCommand(backupOptions, cmd...)
|
|
|
|
case TypeVolume:
|
|
|
|
case TypeVolume:
|
|
|
|
ok := CheckIfVolumeExists(l.From[0])
|
|
|
|
ok := utils.CheckIfVolumeExists(l.From[0])
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
errors = append(errors, fmt.Errorf("volume \"%s\" does not exist", l.From[0]))
|
|
|
|
errors = append(errors, fmt.Errorf("volume \"%s\" does not exist", l.From[0]))
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -277,8 +280,9 @@ func (l Location) Backup(cron bool, specificBackend string) []error {
|
|
|
|
for k, v := range env2 {
|
|
|
|
for k, v := range env2 {
|
|
|
|
env[k+"2"] = v
|
|
|
|
env[k+"2"] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, _, err := ExecuteResticCommand(ExecuteOptions{
|
|
|
|
_, _, err := utils.ExecuteResticCommand(utils.ExecuteOptions{
|
|
|
|
Envs: env,
|
|
|
|
Envs: env,
|
|
|
|
|
|
|
|
Global: GetConfig().Global,
|
|
|
|
}, "copy", md.SnapshotID)
|
|
|
|
}, "copy", md.SnapshotID)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -335,8 +339,9 @@ func (l Location) Forget(prune bool, dry bool) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
options := ExecuteOptions{
|
|
|
|
options := utils.ExecuteOptions{
|
|
|
|
Envs: env,
|
|
|
|
Envs: env,
|
|
|
|
|
|
|
|
Global: GetConfig().Global,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd := []string{"forget", "--tag", l.getLocationTags()}
|
|
|
|
cmd := []string{"forget", "--tag", l.getLocationTags()}
|
|
|
|
if prune {
|
|
|
|
if prune {
|
|
|
@ -346,7 +351,7 @@ func (l Location) Forget(prune bool, dry bool) error {
|
|
|
|
cmd = append(cmd, "--dry-run")
|
|
|
|
cmd = append(cmd, "--dry-run")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd = append(cmd, combineAllOptions("forget", l, backend)...)
|
|
|
|
cmd = append(cmd, combineAllOptions("forget", l, backend)...)
|
|
|
|
_, _, err = ExecuteResticCommand(options, cmd...)
|
|
|
|
_, _, err = utils.ExecuteResticCommand(options, cmd...)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|