Sam Doran

My little corner of the Internet

Backing Up VyOS Configuration

I’ve been doing a lot of work recently with VyOS1, the really amazing open source2 Linux based router operating system. A co-worker of mine showed it to me when we needed a capable router in our development environment and we didn’t feel like waiting for finance to approve a Cisco purchase. I have to admit I didn’t quite get it at first. Linux is an OS, not a router! That’s what IOS3 is for! But after digging into it a bit for a budget constrained side project, I’m totally hooked. And I learned, unequivocally, that Linux can function as a very capable router.

One of the oddities about VyOS is the show configuration command doesn’t produce copy/pastable output. This was initially frustrating to me as someone who is accustomed to the way IOS, ASA OS, and NX-OS work: what you type on the command line is exactly what gets put in the running config. And you can copy and paste bits from a saved config to reuse those settings in other devices.

To get similar behavior out of VyOS, run show configuration commands. You can parse this using our friend the pipe character (|) and the match command followed by a pattern4 like so:

show configuration commands | match interfaces

I wrote a simple script5 to save the running configuration to date stamped file. This could probably get fancier and scp it somewhere, but I just put it on the router itself in my home directory and grab it using an SFTP client.

VyOS Backup
1
2
3
4
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template

run show configuration commands > $HOME/$(date +%Y%m%d-%H%M%S)_$(hostname).txt

Happy routing! And don’t forget to always backup your config!

  1. I use “Vyatta”, “VyOS”, and “EdgeRouter” interchangeably, for better or for worse.

  2. Well, it’s technically no longer open source since Brocade bought them. But VyOS and EdgeRouter are healthy open source forks. That’s what I’ve been using.

  3. Cisco IOS, not that iOS.

  4. This feels like fgrep is being run behind the scenes. Very similiar to the Cisco | include command.

  5. There are a few idiosyncrasies to scripting with VyOS outlined here.