diff --git a/.gitignore b/.gitignore index 6e0b016..ffd4982 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,11 @@ router_backup + +# Debian packaging artifacts +debian/.debhelper/ +debian/.gocache/ +debian/go/ +debian/router-backup/ +debian/*.substvars +debian/debhelper-build-stamp +debian/*.debhelper + diff --git a/Makefile b/Makefile index ddc9a83..808e9e5 100644 --- a/Makefile +++ b/Makefile @@ -36,12 +36,26 @@ fmt: @echo "Formatting Go code..." cd $(SOURCE_DIR) && go fmt ./... +# Build Debian package +.PHONY: pkg-deb +pkg-deb: + fakeroot dpkg-buildpackage -us -uc -b + +# Clean package artifacts +.PHONY: clean-pkg +clean-pkg: + @echo "Cleaning package artifacts..." + @rm -f *.deb + @echo "Package cleanup complete" + # Show help .PHONY: help help: @echo "Available targets:" - @echo " build - Build the router_backup binary" - @echo " clean - Remove build artifacts" - @echo " test - Run tests" - @echo " fmt - Format Go code" - @echo " help - Show this help message" \ No newline at end of file + @echo " build - Build the router_backup binary" + @echo " clean - Remove build artifacts" + @echo " test - Run tests" + @echo " fmt - Format Go code" + @echo " pkg-deb - Create Debian package" + @echo " clean-pkg - Remove package artifacts" + @echo " help - Show this help message" diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..be1b351 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,10 @@ +router-backup (1.0.0) stable; urgency=low + + * Initial release + * SSH Router Backup Tool with YAML configuration + * Support for multiple device types (srlinux, eos) + * SSH agent authentication support + * Command output concatenation with headers + * Go implementation for better performance + + -- Pim van Pelt Sat, 05 Jul 2025 23:55:00 +0100 \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..9afb4b4 --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: router-backup +Section: net +Priority: optional +Maintainer: Pim van Pelt +Build-Depends: debhelper-compat (= 12), golang-go +Standards-Version: 4.5.0 + +Package: router-backup +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, openssh-client +Description: SSH Router Backup Tool + A tool for backing up router configurations via SSH. + Supports multiple device types and YAML configuration. diff --git a/debian/debhelper-build-stamp b/debian/debhelper-build-stamp new file mode 100644 index 0000000..b5b4f2c --- /dev/null +++ b/debian/debhelper-build-stamp @@ -0,0 +1 @@ +router-backup diff --git a/debian/files b/debian/files new file mode 100644 index 0000000..6ffaba7 --- /dev/null +++ b/debian/files @@ -0,0 +1,2 @@ +router-backup_1.0.0_amd64.buildinfo net optional +router-backup_1.0.0_amd64.deb net optional diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..8645242 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,3 @@ +#!/bin/bash +echo 'Router Backup installed successfully.' +echo 'Example config at /etc/router-backup/config.yaml.example' \ No newline at end of file diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..50d0835 --- /dev/null +++ b/debian/rules @@ -0,0 +1,25 @@ +#!/usr/bin/make -f + +%: + dh $@ + +override_dh_auto_build: + cd src && go build -o ../router_backup router_backup.go + +override_dh_auto_install: + mkdir -p debian/router-backup/usr/bin + mkdir -p debian/router-backup/etc/router-backup + mkdir -p debian/router-backup/usr/share/man/man1 + cp router_backup debian/router-backup/usr/bin/ + cp config.yaml debian/router-backup/etc/router-backup/config.yaml.example + cp docs/router_backup.1 debian/router-backup/usr/share/man/man1/ + gzip debian/router-backup/usr/share/man/man1/router_backup.1 + +override_dh_auto_clean: + rm -f router_backup + +override_dh_auto_test: + # Skip tests for now + +override_dh_dwz: + # Skip dwz compression due to Go binary format \ No newline at end of file diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..9f67427 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) \ No newline at end of file diff --git a/docs/router_backup.1 b/docs/router_backup.1 new file mode 100644 index 0000000..1370c67 --- /dev/null +++ b/docs/router_backup.1 @@ -0,0 +1,102 @@ +.TH ROUTER_BACKUP 1 "July 2025" "router-backup 1.0.0" "User Commands" +.SH NAME +router_backup \- SSH Router Backup Tool +.SH SYNOPSIS +.B router_backup +.RI --config " CONFIG_FILE" +.RI [ --git-repo " DIRECTORY" ] +.RI [ --password " PASSWORD" ] +.RI [ --key-file " KEYFILE" ] +.RI [ --port " PORT" ] +.SH DESCRIPTION +.B router_backup +is a tool for backing up router configurations via SSH. It connects to multiple routers defined in a YAML configuration file and executes commands, saving the output to files. +.PP +The tool supports multiple device types with predefined command sets, SSH agent authentication, and automatic file organization. +.SH OPTIONS +.TP +.BR --config " \fICONFIG_FILE\fR" +YAML configuration file path (required) +.TP +.BR --git-repo " \fIDIRECTORY\fR" +Git repository directory for command output files (default: /tmp) +.TP +.BR --password " \fIPASSWORD\fR" +SSH password for authentication +.TP +.BR --key-file " \fIKEYFILE\fR" +SSH private key file path +.TP +.BR --port " \fIPORT\fR" +SSH port number (default: 22) +.TP +.BR --help +Show help message +.SH CONFIGURATION +The configuration file uses YAML format with two main sections: +.SS types +Define device types with their command sets: +.PP +.EX +types: + srlinux: + commands: + - show version + - show platform linecard +.EE +.SS devices +Define individual devices: +.PP +.EX +devices: + router1: + user: admin + type: srlinux +.EE +.SH AUTHENTICATION +Authentication is attempted in the following order: +.IP 1. +SSH agent (if SSH_AUTH_SOCK environment variable is set) +.IP 2. +Specified key file (--key-file option) +.IP 3. +Default SSH keys (~/.ssh/id_rsa, ~/.ssh/id_ed25519, ~/.ssh/id_ecdsa) +.IP 4. +Password authentication (--password option) +.SH OUTPUT +For each device, a text file named after the hostname is created in the specified directory. Each command output is prefixed with "## COMMAND: " for easy identification. +.SH EXAMPLES +.TP +Basic usage: +.EX +router_backup --config /etc/router-backup/config.yaml +.EE +.TP +Custom output directory: +.EX +router_backup --config config.yaml --git-repo /home/user/backups +.EE +.TP +Using password authentication: +.EX +router_backup --config config.yaml --password mysecretpass +.EE +.SH FILES +.TP +.I /etc/router-backup/config.yaml.example +Example configuration file +.SH EXIT STATUS +.TP +.B 0 +Success +.TP +.B 1 +General error (configuration file not found, authentication failure, etc.) +.SH AUTHOR +Written by Pim van Pelt. +.SH REPORTING BUGS +Report bugs to +.SH SEE ALSO +.BR ssh (1), +.BR ssh-agent (1), +.BR dpkg (1) \ No newline at end of file