2023-02-02 05:45:23 +00:00
// backup.go
// Copyright (C) Andrew Woodlee 2023
// License: Apache-2.0
2023-01-10 04:18:56 +00:00
package cmd
import (
"git.andrewnw.xyz/CyberShell/backy/pkg/backy"
"github.com/spf13/cobra"
)
var (
backupCmd = & cobra . Command {
2023-07-02 02:46:54 +00:00
Use : "backup [--lists=list1,list2,... | -l list1, list2,...]" ,
2023-01-10 04:18:56 +00:00
Short : "Runs commands defined in config file." ,
2023-07-02 02:46:54 +00:00
Long : "Backup executes commands defined in config file.\nUse the --lists or -l flag to execute the specified lists. If not flag is not given, all lists will be executed." ,
2023-02-19 04:42:15 +00:00
Run : Backup ,
2023-01-10 04:18:56 +00:00
}
)
2023-01-20 08:42:52 +00:00
// Holds command list to run
2023-02-02 05:45:23 +00:00
var cmdLists [ ] string
2023-01-10 04:18:56 +00:00
func init ( ) {
2023-01-17 06:55:28 +00:00
2023-02-12 05:50:19 +00:00
backupCmd . Flags ( ) . StringSliceVarP ( & cmdLists , "lists" , "l" , nil , "Accepts comma-separated names of command lists to execute." )
2023-01-10 04:18:56 +00:00
}
2023-01-17 06:55:28 +00:00
func Backup ( cmd * cobra . Command , args [ ] string ) {
2023-02-02 05:45:23 +00:00
backyConfOpts := backy . NewOpts ( cfgFile , backy . AddCommandLists ( cmdLists ) )
backyConfOpts . InitConfig ( )
2023-05-12 05:42:14 +00:00
2023-02-02 05:45:23 +00:00
config := backy . ReadConfig ( backyConfOpts )
2023-05-12 05:42:14 +00:00
2023-07-02 02:46:54 +00:00
config . RunListConfig ( "" , backyConfOpts )
2023-03-10 22:01:02 +00:00
for _ , host := range config . Hosts {
if host . SshClient != nil {
host . SshClient . Close ( )
}
}
2023-01-10 04:18:56 +00:00
}