Using rsync to make OpenWrt image backup

Hello,

I am running OpenWrt on an sd card on a Pi4. I want to make an image backup of the sd card. I understand this is likely overkill because I could make a settings and packages list backup and restore them on to a fresh firmware download BUT I want to try and get this approach with rsync to work.

My idea is to rsync the boot and root file systems from the sd card to archives. Then when I want to restore the backup archives I would create the partitions and file systems on an sd card and just rsync the archives back onto that as described here.. this is better than using the dd command apparently.

My question:
When taking a backup of the rootfs which folders can I exclude from the backup?

All of these?

/dev
/lost+found
/mnt
/proc
/run
/sys
/tmp

Any others?

Cheers.

There was a similar thread not long ago.

In that thread, I asked some questions that might be relevant to your situation and help you determine if it is worth bothering with a backup method beyond what is already standard.... especially the bit about how frequently you might be changing your configuration or have other data that needs to be maintained/backed up.

Take a look at that discussion and ping back here with answers and new questions.

EDIT: Oh... wait, it was you who created the original thread... Any particular reason you created a new thread? Why not just continue the previous one?

2 Likes

@psherman Hello again yes I created that thread which is closed now so I don't think I can post to it anymore. I have sort of come full circle since then. I understand now how to make settings and opkg.installed backups so I understand it mostly would be easiest to restore a working system by flashing the latest firmware then re-installing a packages list and a settings backup.

I also got a script working that can do a total image backup of the sd card using dd but noticed that it doesn't seem to capture recent edits I have made to scripts and files on the sd card... I think I would first have to reboot then run the dd command... I tried something like:

imagesPath="/mnt/usb/openwrt/BackupOfImages/"
image_file=${imagesPath}OpenWrt-Image-$(date "+%Y-%m-%d-%H-%M-%S").img.gz
sync
dd if=/dev/mmcblk0 bs=4M count=300 | pv | gzip > $image_file

But when gunzip and mount that .img file recent edits I may have made to files in OpenWrt just before I made that image backup are not in the image backup.

I thought I'd try out something you actually suggested and see can I just use rsync to backup the boot and root file systems that could then be copied in to an sd card partitioned and formatted with the correct file systems.

Do you know which of the directories in OpenWrt do not need to be backed up because maybe they are generated on boot up?

Cheers,

Flex

Ah.. now I understand. To be clear, my suggestion about rsync is theoretical -- I think it should work, but I've never tried.

I think you can omit all of those... you certainly do not need /tmp (and /var actually maps to /tmp). I think /run is similarly not needed (I'm not seeing it on my system at all). /lost+found shoaled be unnecessary, /mnt is empty until a device is mounted there (system generated). /proc and /sys probably aren't necessary either, but I'm not entirely certain.

I think you'll just need to experiment. Run rsync and then restore it to another card. Then try specifically removing each of the directories and see what happens.

1 Like

I am trying to make an rsync backup of the OpenWrt root file system.

This is the rsync command I think I need to use...

rsync -aAXinv --exclude={"/dev/","/proc/","/sys/","/tmp/","/mnt/*","/lost+found"} --log-file=/mnt/usb/openwrt/BackupOfImages/rsynclog.log / /mnt/usb/openwrt/BackupOfImages/rsyncpartitions

But when I run that I get the error:

rsync: ACLs are not supported on this client
rsync error: syntax or usage error (code 1) at main.c(1746) [client=3.2.3]

Questions:

  1. Do I need -AX options in the rsync command to copy preserving ACLs and xAttr? I have read that things might not work if they are not included.
  2. Are there any plans to update the rsync client in the opkg feeds to include this functionality? I see someone made a patched version years ago but not sure if safe to use that or how.

Update
This article talks about extended file system attributes on Linux. In order to use (?some) extended attributes he file system needs to be mounted with the user_xattr mount option. To set ACLs (Access Control Lists) on files, the filesystem needs to be mounted with the acl mount option. No file systems on OpenWrt are apparently mounted with those options.

So I guess I can conclude that the -AX option in rsync is redundant when it comes to backing up OpenWrt file systems? They don't support ACLs and x-attr anyway? I'll ask in the developer section as well.

Cheers,

Flex

All files are owned (and group) as root. I don’t believe I have ever seen any extended attributes (as you mention). Presumably all you need to do is ensure that the files maintain their standard Linux permissions and you should be good.

1 Like

Turns out I had a lot of obstacles to over come with this. This thread covers how I created an image file that rsync'd backups of the boot and root file systems can be restored to and then boot up.

I will post again the full solution... within the next 10 days!

Flex

The less you read and write to the router's flash, the better it is for your router.

That's why it's better to avoid full-inclusive backups and prefer selective file-level sysupgrade backup.

2 Likes