rename --git-repo to --output-dir again

This commit is contained in:
2025-07-06 00:17:37 +00:00
parent c84986a443
commit bf80fd057d
2 changed files with 11 additions and 11 deletions

View File

@ -4,7 +4,7 @@ router_backup \- SSH Router Backup Tool
.SH SYNOPSIS .SH SYNOPSIS
.B router_backup .B router_backup
.RI --config " CONFIG_FILE" .RI --config " CONFIG_FILE"
.RI [ --git-repo " DIRECTORY" ] .RI [ --output-dir " DIRECTORY" ]
.RI [ --password " PASSWORD" ] .RI [ --password " PASSWORD" ]
.RI [ --key-file " KEYFILE" ] .RI [ --key-file " KEYFILE" ]
.RI [ --port " PORT" ] .RI [ --port " PORT" ]
@ -18,8 +18,8 @@ The tool supports multiple device types with predefined command sets, SSH agent
.BR --config " \fICONFIG_FILE\fR" .BR --config " \fICONFIG_FILE\fR"
YAML configuration file path (required) YAML configuration file path (required)
.TP .TP
.BR --git-repo " \fIDIRECTORY\fR" .BR --output-dir " \fIDIRECTORY\fR"
Git repository directory for command output files (default: /tmp) Output directory for command output files (default: /tmp)
.TP .TP
.BR --password " \fIPASSWORD\fR" .BR --password " \fIPASSWORD\fR"
SSH password for authentication SSH password for authentication
@ -74,7 +74,7 @@ router_backup --config /etc/router-backup/config.yaml
.TP .TP
Custom output directory: Custom output directory:
.EX .EX
router_backup --config config.yaml --git-repo /home/user/backups router_backup --config config.yaml --output-dir /home/user/backups
.EE .EE
.TP .TP
Using password authentication: Using password authentication:

View File

@ -124,13 +124,13 @@ func (rb *RouterBackup) RunCommand(command string) (string, error) {
} }
// BackupCommands runs multiple commands and saves outputs to files // BackupCommands runs multiple commands and saves outputs to files
func (rb *RouterBackup) BackupCommands(commands []string, gitRepo string) error { func (rb *RouterBackup) BackupCommands(commands []string, outputDir string) error {
if err := os.MkdirAll(gitRepo, 0755); err != nil { if err := os.MkdirAll(outputDir, 0755); err != nil {
return fmt.Errorf("failed to create directory %s: %v", gitRepo, err) return fmt.Errorf("failed to create directory %s: %v", outputDir, err)
} }
filename := fmt.Sprintf("%s.txt", rb.hostname) filename := fmt.Sprintf("%s.txt", rb.hostname)
filepath := filepath.Join(gitRepo, filename) filepath := filepath.Join(outputDir, filename)
// Truncate file at start // Truncate file at start
file, err := os.Create(filepath) file, err := os.Create(filepath)
@ -220,7 +220,7 @@ func main() {
var password string var password string
var keyFile string var keyFile string
var port int var port int
var gitRepo string var outputDir string
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "router_backup", Use: "router_backup",
@ -286,7 +286,7 @@ func main() {
continue continue
} }
err = backup.BackupCommands(commands, gitRepo) err = backup.BackupCommands(commands, outputDir)
backup.Disconnect() backup.Disconnect()
if err != nil { if err != nil {
@ -305,7 +305,7 @@ func main() {
rootCmd.Flags().StringVar(&password, "password", "", "SSH password") rootCmd.Flags().StringVar(&password, "password", "", "SSH password")
rootCmd.Flags().StringVar(&keyFile, "key-file", "", "SSH private key file path") rootCmd.Flags().StringVar(&keyFile, "key-file", "", "SSH private key file path")
rootCmd.Flags().IntVar(&port, "port", 22, "SSH port") rootCmd.Flags().IntVar(&port, "port", 22, "SSH port")
rootCmd.Flags().StringVar(&gitRepo, "git-repo", "/tmp", "Git repository directory for command output files") rootCmd.Flags().StringVar(&outputDir, "output-dir", "/tmp", "Output directory for command output files")
rootCmd.MarkFlagRequired("config") rootCmd.MarkFlagRequired("config")