@frollic , I was hoping there was an automated way to send them straight to a directory on a connected device (and cut out a directory on router as middleman). Would using scp allow for that - mounting the device directory in OpenWRT using samba or NFS, and then backup straight to that directory? I'm only familiar with samba as a file transfer protocol thus far.
@brada4 thanks, I'll have to look into git a bit more, as I'm relatively unfamiliar. I'm imagining you're not referring to github?
@efahl can you please explain your script a bit more?
No github, just track file changes on devices using any version control system you are ok with, it can be git. subversion, mercurial, cvs . To track config changes on the devices and backtrack when your fingers press wrong keys.
Yup, like @frollic says, we create no file on the router, as the -b - says "do a backup, with the output going to the file -, which is linux idiom for stdout". So, via ssh we run the sysupgrade command on the router device, sending the output to the tty, but we add a redirect to intercept it and save it to a local file. You can run this on anything that has ssh access to the router and access to the backup host's file system, not just on the backup host itself (although that's usually most convenient).
All the rest with $datestamp and $router just make the output file name unique. Here's the date format I prefer, but it's completely up to you if you want to use the same.
Now, I'm curious if this script that creates a backup after every OpenWRT configuration change could be integrated with the SSH method @efahl proposed?
Not really. That script implements a service on the device that does backups there. My solution is purely off-device, it simply sends a command from a remote host to get the backup data local to itself.
You could change that script to write the backups to a mounted file system on a NAS or whatever, or to do an scp of the backup to a remote host, but everything will be running on the OpenWrt side and not on the remote machine.