{backup,snapshot}: Rename common code to export
This commit is contained in:
parent
b3a827e042
commit
bf57c0d5a6
14 changed files with 145 additions and 133 deletions
|
|
@ -9,9 +9,9 @@ import (
|
|||
)
|
||||
|
||||
// Backup is the 'backup' command
|
||||
var Backup wisski_distillery.Command = backupC{}
|
||||
var Backup wisski_distillery.Command = backup{}
|
||||
|
||||
type backupC struct {
|
||||
type backup struct {
|
||||
NoPrune bool `short:"n" long:"no-prune" description:"Do not prune older backup archives"`
|
||||
StagingOnly bool `short:"s" long:"staging-only" description:"Do not package into a backup archive, but only create a staging directory"`
|
||||
ConcurrentSnapshots int `short:"c" long:"concurrent-snapshots" description:"Maximum number of concurrent snapshots" default:"2"`
|
||||
|
|
@ -20,7 +20,7 @@ type backupC struct {
|
|||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
func (backupC) Description() wisski_distillery.Description {
|
||||
func (backup) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: core.Requirements{
|
||||
NeedsDistillery: true,
|
||||
|
|
@ -35,29 +35,25 @@ var errBackupFailed = exit.Error{
|
|||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
func (bk backupC) Run(context wisski_distillery.Context) error {
|
||||
func (bk backup) Run(context wisski_distillery.Context) error {
|
||||
dis := context.Environment
|
||||
|
||||
// prune old backups
|
||||
if !bk.NoPrune {
|
||||
defer logging.LogOperation(func() error {
|
||||
return dis.SnapshotManager().PruneBackups(context.IOStream)
|
||||
return dis.SnapshotManager().PruneExports(context.IOStream)
|
||||
}, context.IOStream, "Pruning old backups")
|
||||
}
|
||||
|
||||
// do the handling
|
||||
err := dis.SnapshotManager().HandleSnapshotLike(context.IOStream, snapshots.SnapshotFlags{
|
||||
err := dis.SnapshotManager().MakeExport(context.IOStream, snapshots.ExportTask{
|
||||
Dest: bk.Positionals.Dest,
|
||||
Slug: "",
|
||||
Title: "Backup",
|
||||
StagingOnly: bk.StagingOnly,
|
||||
|
||||
Do: func(dest string) snapshots.SnapshotLike {
|
||||
backup := dis.SnapshotManager().NewBackup(context.IOStream, snapshots.BackupDescription{
|
||||
Dest: dest,
|
||||
ConcurrentSnapshots: bk.ConcurrentSnapshots,
|
||||
})
|
||||
return &backup
|
||||
Instance: nil,
|
||||
|
||||
BackupDescription: snapshots.BackupDescription{
|
||||
ConcurrentSnapshots: bk.ConcurrentSnapshots,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ import (
|
|||
// Config is the configuration command
|
||||
var Config wisski_distillery.Command = cfg{}
|
||||
|
||||
type cfg struct {
|
||||
}
|
||||
type cfg struct{}
|
||||
|
||||
func (s cfg) Description() wisski_distillery.Description {
|
||||
func (c cfg) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: core.Requirements{
|
||||
NeedsDistillery: true,
|
||||
|
|
@ -21,7 +20,7 @@ func (s cfg) Description() wisski_distillery.Description {
|
|||
}
|
||||
}
|
||||
|
||||
func (s cfg) Run(context wisski_distillery.Context) error {
|
||||
func (cfg) Run(context wisski_distillery.Context) error {
|
||||
context.Printf("%#v", context.Environment.Config)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,28 +35,21 @@ var errSnapshotFailed = exit.Error{
|
|||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
func (bi snapshot) Run(context wisski_distillery.Context) error {
|
||||
func (sn snapshot) Run(context wisski_distillery.Context) error {
|
||||
dis := context.Environment
|
||||
|
||||
// find the instance!
|
||||
instance, err := dis.Instances().WissKI(bi.Positionals.Slug)
|
||||
instance, err := dis.Instances().WissKI(sn.Positionals.Slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// do a snapshot of it!
|
||||
err = dis.SnapshotManager().HandleSnapshotLike(context.IOStream, snapshots.SnapshotFlags{
|
||||
Dest: bi.Positionals.Dest,
|
||||
Slug: bi.Positionals.Slug,
|
||||
Title: "Snapshot",
|
||||
StagingOnly: bi.StagingOnly,
|
||||
err = dis.SnapshotManager().MakeExport(context.IOStream, snapshots.ExportTask{
|
||||
Dest: sn.Positionals.Dest,
|
||||
StagingOnly: sn.StagingOnly,
|
||||
|
||||
Do: func(dest string) snapshots.SnapshotLike {
|
||||
snapshot := dis.SnapshotManager().NewSnapshot(instance, context.IOStream, snapshots.SnapshotDescription{
|
||||
Dest: dest,
|
||||
})
|
||||
return &snapshot
|
||||
},
|
||||
Instance: &instance,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue