Backing up OpenWRT

A Tech article with View Comments posted 8 February 2007.
Tags: ,

I recently got a Linksys WRT54GL router, and I installed OpenWRT, an open-source Linux firmware. But I ran into a sticky problem – how do I back it up? Using scp doesn’t work because scp doesn’t have a way to ignore symlinks. Heavier tools (like rsync) would be great, but they are too heavy for a tiny embedded system like this. This might seem obvious to some, but this way worked quite well:

ssh user@domain.com "tar cv /bin /etc /lib /sbin /tmp /usr /www" > openwrt.tar

Why not gzip the output? Well, remember that the WRT54GL is a tiny embedded system – 16M of RAM and 4M of flash memory. You can’t zip the whole thing up because piping tar to gzip on my router because it would use up all of the available free RAM. By only using the bare minimum (tar) you can successfully get this to run in about 600K of free memory.

Why enumerate all of those folders? OpenWRT routers have /jffs and /rom, among other things, which are overlayed to give you the image you have of the root filesystem. Excluding those (and /dev and /proc) skips a lot of unnecessary file copying.

The resulting file size was 6.5M, and when gzipped it was 2.6M, which agrees quite well with the 2.9M that I expected based on the disk usage in the compressed JFFS filesystem.

I’m planning an extensive “Asterisk on WRT54GL” tutorial soon, so if you’re interested in what you can do with a little bit of Linux and a tiny, in-expensive wireless router, check back with me in a few weeks.

View Comments to “Backing up OpenWRT”

  1. TheJew says:

    Of course you can gzip it on the other PC, i.e.,

    ssh user@domain.com “tar cv /bin /etc /lib /sbin /tmp /usr /www” | gzip -c > openwrt.tgz

  2. It's a tradeoff – yeah, that moves the CPU overhead off of the router, but it pushes more bandwidth onto the network. Probably a reasonable tradeoff, though, considering that the backuppc server and the router are now connected by ethernet. At the time I wrote this in 2007, though, the server was on a wireless connection.

  3. Although not quite the same, what about backing up only the /jffs? Theoretically that would be the only real data or modifications made to the system?

  4. That would definitely do what you think it does. I would ask what's more useful, though: a snapshot of the whole system, or a snapshot of your changes relative to a particular install. If you also backed up the particular installer used to generate the system, then this is a good option. To restore, just install from the old installer, then restore /jffs on top of it. But without the exact version of installer, you don't know exactly how your modifications and settings might interact with that particular base installation's bugs, feature, and idiosyncrasies.

    Besides, BackupPC handles things like redundant data very well, and the redundant data in question is only a few tens of megabytes.

Leave a Reply

blog comments powered by Disqus