wisski-cloud-distillery/internal/component/control/backup.go
Tom Wiesing 5cd5ae9be2
'wdcli backup': Rework backup process
This commit reworks the backup process to dynamically find the list of
components.
2022-09-17 16:34:07 +02:00

48 lines
1 KiB
Go

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,
}
}