r/opnsense • u/djdawson • 7h ago
SCP Config Backup Option
I've been running OPNsense for a couple years now and try to remember to export the XML config after changes via the web interface and check it into git on my Mac (I just use the local git CLI commands). I've been thinking about automating this a bit and have seen the options for doing this via a community plugin or two, as well as doing this via the API from an external system. One option I haven't seen so far (though I'm sure I'm not the first to think of it) is to just use "scp" from an external system to download the config instead of using the API. In its simplest form it's a one-liner that'll just grab the current config file to the local system. This assumes you've set up the appropriate user permissions as well as ssh access with a shared key, but I've had that configured for a long time. I also slapped together a little shell script to grab the current config file but only save it if it's different from the previously downloaded config as a test, and I'm thinking that I might just let multiple timestamped copies of the config accumulate rather than check them into git, since this would mimic the functionality of the System --> Configuration --> History feature of the web interface. I also still have my old git repo and plan to keep it current until I settle on one final solution, and it'd be easy to add that functionality to my script. I'll probably also end up fighting with cron before too long, too.
None of this is especially fancy or complicated, but since I didn't remember seeing the "scp" download method mentioned for config backups I thought I'd share it in case others find it useful. It definitely seems simpler than the API option, but it's a more special case so if you're wanting to automate other things then learning the API would be worth the effort. I happen to use a Mac so the Terminal makes this easy, but it'd be just as simple on any Linux distro out there, and I expect it would also work on Windows if you have the Windows Subsystem for Linux (WSL) installed.


