RPI Full backup

Hi everyone,

I Finally got to try openwrt on my spare rpi2 and after few fiddling it works just great with 2 ports (extra one using a gigabit usb dongle).

Now after setting everthing up i want to create a full backup image of the sd card (on a weekly schedule without of course bringing the router down and copy the sd card content).

I am using the squashfs version which creates an overlay of f2fs.

So when using a script with dd if=/dev/mmcblk0 .... i get an image and when i write it to an extra sd card and boot from there i get an "old verison" of my file system (seems since boot ?).

I did some more tests , and changed few things via luci , if i unplugged the power after about 10 seconds , the and plugged it back , the setting was not really saved.

Did same test again but waited 2 minutes , and setting was saved.

I understand the f2fs keeps some buffer and does not write immediatlly to the sd card.

I have 2 questions :

1.How i can find/set this interval ?

2.No matter what i tried , i cant seem to find a way to create an image of the sd card with updated data , is there some command that i can execute via ssh so it will flush all data to the sd card (like on normal reboot)

I am quite new to openwrt so and no linux expert so if am missing something i would glad to have a better explanation to this situation (since most wikis are not for RPI but for routers with limited storage capabilities)

Thanks in advance.

sync

will flush all buffers to the storage

but if you want to take a backup, you're probably best off to
mount -o remount,ro ...

so the filesystem isn't changing during the backup.

Also, this process produces ENORMOUS files. You're probably better off just connecting to LUCI and taking a backup of the settings. Then, you can restore by installing a default install from the OpenWrt site, and installing any missing packages, and uploading your settings backup.

Thanks for your answer

First , regarding your remark of enormous file , i am of course limiting the size of the created image with the following

dd if=/dev/mmcblk0 bs=4M count=75 | pv > /mnt/openwrt/openwrt_$(date +"%Y%m%d%H%M%S").img

This way only the first 300mb are backed up (you can also gzip the file) which is enough (the boot fat partition is 20 mb and overlay is 256mb)
Also you get an exact full copy of your setup and you do not need to reinstall packages or what ever you changed.

As for my problem with "out of date files" in the created img file , I do believe i tried the sync command and it did not work. (i will try again i guess)

As for your second suggestion

mount -o remount,ro ...

you meant something like the following

mount -o remount /overlay

Can you supply a full command to force the overlay to be fully written to the sd card ?

Thanks in advance.

mount -o remount,ro /overlay

will force the whole thing to be written, and prevent it from changing during your backup. Don't forget to mount -o remount,rw /overlay at the end.

Tested the sync again and also mount/remount , both did not work. the dd command generates an image from last boot :neutral_face:

Any other ideas ?

Thanks in advance.

perhaps the f2fs needs you to actually unmount it rather than just remount,ro before snapshotting?

Tried also

umount /overlay

Before calling dd and after lot of testing i found that no matter what i try , i can not seem to find way to make the system to flush all data to the sdcard so dd would create an exact copy.

What i did find out , that after boot , sync command seems to matter.

I created a simple file , created an image using dd to cifs mount.

called sync , and again created an image using dd to cifs mount.

Now using a second rpi system i tested the newly written sd card.

Wrote the image which was created without calling sync on a different sd card , the file was not there.

Wrote the image which was created after calling sync the file was there.

After about 3-4 hours , did the same process again , but both images did not contain the newly created file (other file of course) .

Only way i could see new files was to reboot and create a new dd image and write that image on new sd card and load it on a second rpi system.

I guess i am missing the internal working of openwrt->overlay or maybe f2fs is not "dd friendly" in this case.

If someone has an other ideas/soultions i would be most grateful :slight_smile:

I think dd is not your friend here... just tar the entire filesystem.

Just to update if any one else would like to accomplish this.

I wind up using ext4 instead of squashfs image which also solved this issue for me , using ext4 version works just fine with dd and image backup works great.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.