2023-02-01 23:45:23 -06:00
// backup.go
// Copyright (C) Andrew Woodlee 2023
// License: Apache-2.0
2023-01-09 22:18:56 -06:00
package cmd
import (
"git.andrewnw.xyz/CyberShell/backy/pkg/backy"
"github.com/spf13/cobra"
)
var (
backupCmd = & cobra . Command {
2025-02-08 15:17:34 -06:00
Use : "backup [--lists=list1 --lists list2 ... | -l list1 -l list2 ...]" ,
Short : "Runs commands defined in config file. Use -l flag multiple times to run multiple lists." ,
2023-07-01 21:46:54 -05: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-18 22:42:15 -06:00
Run : Backup ,
2023-01-09 22:18:56 -06:00
}
)
2023-01-20 02:42:52 -06:00
// Holds command list to run
2023-02-01 23:45:23 -06:00
var cmdLists [ ] string
2023-01-09 22:18:56 -06:00
func init ( ) {
2025-02-08 15:17:34 -06:00
parseS3Config ( )
2023-01-17 00:55:28 -06:00
2025-02-08 15:17:34 -06:00
backupCmd . Flags ( ) . StringArrayVarP ( & cmdLists , "lists" , "l" , nil , "Accepts comma-separated names of command lists to execute." )
2023-01-09 22:18:56 -06:00
}
2023-01-17 00:55:28 -06:00
func Backup ( cmd * cobra . Command , args [ ] string ) {
2023-02-01 23:45:23 -06:00
backyConfOpts := backy . NewOpts ( cfgFile , backy . AddCommandLists ( cmdLists ) )
backyConfOpts . InitConfig ( )
2025-01-14 09:42:43 -06:00
backyConfOpts . ReadConfig ( )
2023-05-12 00:42:14 -05:00
2023-09-08 23:42:13 -05:00
backyConfOpts . RunListConfig ( "" )
for _ , host := range backyConfOpts . Hosts {
2023-03-10 16:01:02 -06:00
if host . SshClient != nil {
host . SshClient . Close ( )
}
}
2023-01-09 22:18:56 -06:00
}