'wdcli backup': Rework backup process

This commit reworks the backup process to dynamically find the list of
components.
This commit is contained in:
Tom Wiesing 2022-09-17 16:30:32 +02:00
parent 55bee7422d
commit 5cd5ae9be2
No known key found for this signature in database
32 changed files with 361 additions and 279 deletions

View file

@ -0,0 +1,48 @@
package control
import (
"io/fs"
"os"
"path/filepath"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/tkw1536/goprogram/stream"
)
func (*Control) BackupName() string {
return "config"
}
// Backup backups all control plane configuration files into dest
func (control *Control) Backup(io stream.IOStream, dest string) error {
// create the destination directory, TODO: outsource this
if err := os.Mkdir(dest, fs.ModeDir); err != nil {
return err
}
files := control.backupFiles()
for _, src := range files {
dst := filepath.Join(dest, filepath.Base(src)) // destination path
// if the src file does not exist, don't copy it!
if !fsx.IsFile(src) { // TODO: log this somewhere
continue
}
if err := fsx.CopyFile(dst, src); err != nil {
return err
}
}
return nil
}
// backupfiles lists the files to be backed up.
func (control *Control) backupFiles() []string {
return []string{
control.Config.ConfigPath,
control.Config.ExecutablePath(),
control.Config.SelfOverridesFile,
control.Config.GlobalAuthorizedKeysFile,
}
}