redesign started
This commit is contained in:
parent
2daae5cf9e
commit
52d49e70f2
@ -30,7 +30,7 @@ func Execute() error {
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.config/backy/config.yaml)")
|
||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file to read from")
|
||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Sets verbose level")
|
||||
rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
|
||||
}
|
||||
|
@ -10,10 +10,11 @@ import (
|
||||
"git.andrewnw.xyz/CyberShell/backy/pkg/logging"
|
||||
)
|
||||
|
||||
// Host defines a host to which to connect
|
||||
// If not provided, the values will be looked up in the default ssh config file
|
||||
type Host struct {
|
||||
Empty bool
|
||||
Host string
|
||||
UseSSHAgent bool
|
||||
HostName string
|
||||
Port uint16
|
||||
PrivateKeyPath string
|
||||
@ -22,17 +23,11 @@ type Host struct {
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
Empty bool
|
||||
Remote bool
|
||||
RemoteHost Host
|
||||
Cmd string
|
||||
Args []string
|
||||
}
|
||||
type Commands struct {
|
||||
Before Command
|
||||
Backup Command
|
||||
After Command
|
||||
}
|
||||
|
||||
// BackupConfig is a configuration struct that is used to define backups
|
||||
type BackupConfig struct {
|
||||
@ -40,40 +35,12 @@ type BackupConfig struct {
|
||||
BackupType string
|
||||
ConfigPath string
|
||||
|
||||
Cmds Commands
|
||||
Cmd Command
|
||||
}
|
||||
|
||||
/*
|
||||
* Runs a backup configuration
|
||||
*/
|
||||
func (backup BackupConfig) Run() logging.Logging {
|
||||
|
||||
beforeConfig := backup.Cmds.Before
|
||||
beforeOutput := beforeConfig.runCmd()
|
||||
if beforeOutput.Err != nil {
|
||||
return logging.Logging{
|
||||
Output: beforeOutput.Output,
|
||||
Err: beforeOutput.Err,
|
||||
}
|
||||
}
|
||||
backupConfig := backup.Cmds.Backup
|
||||
backupOutput := backupConfig.runCmd()
|
||||
if backupOutput.Err != nil {
|
||||
return logging.Logging{
|
||||
Output: beforeOutput.Output,
|
||||
Err: beforeOutput.Err,
|
||||
}
|
||||
}
|
||||
afterConfig := backup.Cmds.After
|
||||
afterOutput := afterConfig.runCmd()
|
||||
if afterOutput.Err != nil {
|
||||
return afterOutput
|
||||
}
|
||||
return logging.Logging{
|
||||
Output: afterOutput.Output,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (command Command) runCmd() logging.Logging {
|
||||
|
||||
@ -91,7 +58,7 @@ func (command Command) runCmd() logging.Logging {
|
||||
remoteHost.Port = 22
|
||||
remoteHost.Host = command.RemoteHost.Host
|
||||
|
||||
sshc, err := remoteHost.connectToSSHHost()
|
||||
sshc, err := remoteHost.ConnectToSSHHost()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("ssh dial: %w", err))
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func GetSSHConfig(host string) (SshConfig, error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (remoteConfig *Host) connectToSSHHost() (*ssh.Client, error) {
|
||||
func (remoteConfig *Host) ConnectToSSHHost() (*ssh.Client, error) {
|
||||
var sshc *ssh.Client
|
||||
var connectErr error
|
||||
|
||||
|
@ -81,39 +81,5 @@ func CreateConfig(backup backy.BackupConfig) backy.BackupConfig {
|
||||
ConfigPath: backup.ConfigPath,
|
||||
}
|
||||
|
||||
if !backup.Cmds.Before.Empty {
|
||||
newBackupConfig.Cmds.Before.Cmd = backup.Cmds.Before.Cmd
|
||||
newBackupConfig.Cmds.After.Args = backup.Cmds.Before.Args
|
||||
if backup.Cmds.Before.Remote {
|
||||
newBackupConfig.Cmds.Before.RemoteHost.Host = backup.Cmds.Before.RemoteHost.Host
|
||||
newBackupConfig.Cmds.Before.RemoteHost.Port = backup.Cmds.Before.RemoteHost.Port
|
||||
newBackupConfig.Cmds.Before.RemoteHost.PrivateKeyPath = backup.Cmds.Before.RemoteHost.PrivateKeyPath
|
||||
} else {
|
||||
newBackupConfig.Cmds.Before.RemoteHost.Empty = true
|
||||
}
|
||||
}
|
||||
if !backup.Cmds.Backup.Empty {
|
||||
newBackupConfig.Cmds.Backup.Cmd = backup.Cmds.Backup.Cmd
|
||||
newBackupConfig.Cmds.Backup.Args = backup.Cmds.Backup.Args
|
||||
if backup.Cmds.Backup.Remote {
|
||||
newBackupConfig.Cmds.Backup.RemoteHost.Host = backup.Cmds.Backup.RemoteHost.Host
|
||||
newBackupConfig.Cmds.Backup.RemoteHost.Port = backup.Cmds.Backup.RemoteHost.Port
|
||||
newBackupConfig.Cmds.Backup.RemoteHost.PrivateKeyPath = backup.Cmds.Backup.RemoteHost.PrivateKeyPath
|
||||
} else {
|
||||
newBackupConfig.Cmds.Backup.RemoteHost.Empty = true
|
||||
}
|
||||
}
|
||||
if !backup.Cmds.After.Empty {
|
||||
newBackupConfig.Cmds.After.Cmd = backup.Cmds.After.Cmd
|
||||
newBackupConfig.Cmds.After.Args = backup.Cmds.After.Args
|
||||
if backup.Cmds.After.Remote {
|
||||
newBackupConfig.Cmds.After.RemoteHost.Host = backup.Cmds.After.RemoteHost.Host
|
||||
newBackupConfig.Cmds.After.RemoteHost.Port = backup.Cmds.After.RemoteHost.Port
|
||||
newBackupConfig.Cmds.After.RemoteHost.PrivateKeyPath = backup.Cmds.After.RemoteHost.PrivateKeyPath
|
||||
} else {
|
||||
newBackupConfig.Cmds.Before.RemoteHost.Empty = true
|
||||
}
|
||||
}
|
||||
|
||||
return backup
|
||||
return newBackupConfig
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user