wip: backup/restore rise from the ashes
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
decentral1se 2024-10-28 14:32:07 +01:00
parent 1f9b863be0
commit 0e90c0ba75
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
3 changed files with 106 additions and 20 deletions

View File

@ -19,6 +19,30 @@ var snapshotFlag = &cli.StringFlag{
Destination: &snapshot,
}
var retries string
var retriesFlag = &cli.StringFlag{
Name: "retries",
Aliases: []string{"r"},
Usage: "No. retry attempts",
Destination: &retries,
}
var showAll bool
var showAllFlag = &cli.BoolFlag{
Name: "all",
Aliases: []string{"a"},
Usage: "Show all snapshots",
Destination: &showAll,
}
var timestamps bool
var timestampsFlag = &cli.BoolFlag{
Name: "timestamps",
Aliases: []string{"t"},
Usage: "Include timestamps",
Destination: &timestamps,
}
var includePath string
var includePathFlag = &cli.StringFlag{
Name: "path",
@ -27,12 +51,12 @@ var includePathFlag = &cli.StringFlag{
Destination: &includePath,
}
var resticRepo string
var resticRepoFlag = &cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Usage: "Restic repository",
Destination: &resticRepo,
var includeSecrets bool
var includeSecretsFlag = &cli.BoolFlag{
Name: "secrets",
Aliases: []string{"s"},
Usage: "Include secrets",
Destination: &includeSecrets,
}
var appBackupListCommand = cli.Command{
@ -40,7 +64,10 @@ var appBackupListCommand = cli.Command{
Aliases: []string{"ls"},
Flags: []cli.Flag{
snapshotFlag,
showAllFlag,
timestampsFlag,
includePathFlag,
internal.MachineReadableFlag,
},
Before: internal.SubCommandBefore,
Usage: "List all backups",
@ -73,6 +100,14 @@ var appBackupListCommand = cli.Command{
log.Debugf("including INCLUDE_PATH=%s in backupbot exec invocation", includePath)
execEnv = append(execEnv, fmt.Sprintf("INCLUDE_PATH=%s", includePath))
}
if showAll {
log.Debugf("including SHOW_ALL=%s in backupbot exec invocation", showAll)
execEnv = append(execEnv, fmt.Sprintf("SHOW_ALL=%s", showAll))
}
if timestamps {
log.Debugf("including TIMESTAMPS=%s in backupbot exec invocation", timestamps)
execEnv = append(execEnv, fmt.Sprintf("TIMESTAMPS=%s", timestamps))
}
if err := internal.RunBackupCmdRemote(cl, "ls", targetContainer.ID, execEnv); err != nil {
log.Fatal(err)
@ -88,6 +123,8 @@ var appBackupDownloadCommand = cli.Command{
Flags: []cli.Flag{
snapshotFlag,
includePathFlag,
includeSecretsFlag,
internal.IncludeVolumesFlag,
},
Before: internal.SubCommandBefore,
Usage: "Download a backup",
@ -132,11 +169,22 @@ var appBackupDownloadCommand = cli.Command{
log.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
}
if includePath != "" {
log.Debugf("including INCLUDE_PATH=%s in backupbot exec invocation", includePath)
execEnv = append(execEnv, fmt.Sprintf("INCLUDE_PATH=%s", includePath))
}
if includeSecrets {
log.Debugf("including SECRETS=%s in backupbot exec invocation", includeSecrets)
execEnv = append(execEnv, fmt.Sprintf("SECRETS=%s", includeSecrets))
}
if internal.IncludeVolumes {
log.Debugf("including VOLUMES=%s in backupbot exec invocation", internal.IncludeVolumes)
execEnv = append(execEnv, fmt.Sprintf("VOLUMES=%s", internal.IncludeVolumes))
}
if err := internal.RunBackupCmdRemote(cl, "download", targetContainer.ID, execEnv); err != nil {
log.Fatal(err)
}
@ -157,7 +205,7 @@ var appBackupCreateCommand = cli.Command{
Name: "create",
Aliases: []string{"c"},
Flags: []cli.Flag{
resticRepoFlag,
retriesFlag,
},
Before: internal.SubCommandBefore,
Usage: "Create a new backup",
@ -198,9 +246,9 @@ var appBackupCreateCommand = cli.Command{
}
execEnv := []string{fmt.Sprintf("SERVICE=%s", app.Domain)}
if resticRepo != "" {
log.Debugf("including RESTIC_REPO=%s in backupbot exec invocation", resticRepo)
execEnv = append(execEnv, fmt.Sprintf("RESTIC_REPO=%s", resticRepo))
if retries != "" {
log.Debugf("including RETRIES=%s in backupbot exec invocation", retries)
execEnv = append(execEnv, fmt.Sprintf("RETRIES=%s", retries))
}
if err := internal.RunBackupCmdRemote(cl, "create", targetContainer.ID, execEnv); err != nil {
@ -212,11 +260,8 @@ var appBackupCreateCommand = cli.Command{
}
var appBackupSnapshotsCommand = cli.Command{
Name: "snapshots",
Aliases: []string{"s"},
Flags: []cli.Flag{
snapshotFlag,
},
Name: "snapshots",
Aliases: []string{"s"},
Before: internal.SubCommandBefore,
Usage: "List backup snapshots",
UsageText: "abra app backup snapshots <domain> [options]",
@ -256,11 +301,6 @@ var appBackupSnapshotsCommand = cli.Command{
}
execEnv := []string{fmt.Sprintf("SERVICE=%s", app.Domain)}
if snapshot != "" {
log.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
}
if err := internal.RunBackupCmdRemote(cl, "snapshots", targetContainer.ID, execEnv); err != nil {
log.Fatal(err)
}

View File

@ -19,6 +19,22 @@ var targetPathFlag = &cli.StringFlag{
Destination: &targetPath,
}
var noCommands bool
var noCommandsFlag = &cli.BoolFlag{
Name: "no-commands",
Aliases: []string{"nc"},
Usage: "Disable post-restore commands",
Destination: &noCommands,
}
var specificContainer []string
var specificContainerFlag = &cli.StringSliceFlag{
Name: "container",
Aliases: []string{"c"},
Usage: "Restore specific container(s)",
Destination: &specificContainer,
}
var appRestoreCommand = cli.Command{
Name: "restore",
Aliases: []string{"rs"},
@ -26,6 +42,10 @@ var appRestoreCommand = cli.Command{
UsageText: "abra app restore <domain> <service> [options]",
Flags: []cli.Flag{
targetPathFlag,
internal.NoInputFlag,
internal.IncludeVolumesFlag,
specificContainerFlag,
noCommandsFlag,
},
Before: internal.SubCommandBefore,
ShellComplete: autocomplete.AppNameComplete,
@ -51,11 +71,29 @@ var appRestoreCommand = cli.Command{
log.Debugf("including SNAPSHOT=%s in backupbot exec invocation", snapshot)
execEnv = append(execEnv, fmt.Sprintf("SNAPSHOT=%s", snapshot))
}
if targetPath != "" {
log.Debugf("including TARGET=%s in backupbot exec invocation", targetPath)
execEnv = append(execEnv, fmt.Sprintf("TARGET=%s", targetPath))
}
if internal.NoInput {
log.Debugf("including NONINTERACTIVE=%s in backupbot exec invocation", internal.NoInput)
execEnv = append(execEnv, fmt.Sprintf("NONINTERACTIVE=%s", internal.NoInput))
}
if internal.IncludeVolumes {
log.Debugf("including VOLUMES=%s in backupbot exec invocation", internal.IncludeVolumes)
execEnv = append(execEnv, fmt.Sprintf("VOLUMES=%s", internal.IncludeVolumes))
}
if len(specificContainer) > 0 {
for _, specCon := range specificContainer {
log.Debugf("including CONTAINER=%s in backupbot exec invocation", specCon)
execEnv = append(execEnv, fmt.Sprintf("CONTAINER=%s", specCon))
}
}
if err := internal.RunBackupCmdRemote(cl, "restore", targetContainer.ID, execEnv); err != nil {
log.Fatal(err)
}

View File

@ -319,6 +319,14 @@ var AllServicesFlag = &cli.BoolFlag{
Destination: &AllServices,
}
var IncludeVolumes bool
var IncludeVolumesFlag = &cli.BoolFlag{
Name: "volumes",
Aliases: []string{"v"},
Usage: "Include volumes",
Destination: &IncludeVolumes,
}
// SubCommandBefore wires up pre-action machinery (e.g. --debug handling).
func SubCommandBefore(ctx context.Context, cmd *cli.Command) error {
if Debug {