[R4S] Auto restore backup on new firmware from USB Key

Hi,

RC4 popped up and I want to upgrade.

I'm thinking about a restoring workflow wich does allow to just put a new (well made) SD Card and reboot.

(I'm not fan about stopping my network, unplugging cables, booting a new fresh SD Card, restoring backup manually, wiring back and booting)

I need your help to figure up something smarter.

So here is my starters:

I've set up my backup on an USB Key.
I've listed additional packages to request custom build.
Option 1: flash the SD Card, expand it, and somehow restore the backup from my laptop.
Option 2: use the initial script to restore the backup (?) (it would be easier because the squasfs overlay is created at first boot, and I was not able to create it before hand)

I like option 2 better

Have you done something like it ?

EDIT : change original title Restore backup on SD Card from alien OS OR use uci-defaults to restore backup from USB Key

to solve this smaller part, I did this:
I keep the 2 default assigned eth0 and eth1 als LAN1 and WAN, such that I do not need to recable anything to boot a plain image.
my computer used for adminstration is on eth0 even on regular usage. So without recabling, I can boot the plain image and then apply the backup file.

I've done a script that works (sometimes)

https://firmware-selector.openwrt.org/?version=23.05.0-rc4&target=rockchip%2Farmv8&id=friendlyarm_nanopi-r4s

Add some packages

kmod-scsi-core kmod-nls-base kmod-usb-core kmod-lib-crc16 libatomic1 libusb-1.0-0 libevdev libudev-zero usbutils libstdcpp6 gdisk block-mount kmod-fs-exfat kmod-fs-ext4 kmod-usb-storage kmod-usb-ehci kmod-usb2 kmod-usb-xhci-hcd kmod-usb3 kmod-usb-storage-uas kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-utf8 kmod-fs-vfat diffutils blockdev

Put this in the uci-defaults field

cat >/etc/rc.local << 'EOF'
# restore and reboot

if mount | awk '{if ($3 == "/mnt/sda1") { exit -1}} ENDFILE{exit 0}'; then
	mkdir -p /mnt/sda1
	mount /dev/sda1 /mnt/sda1
fi

if [ -f /mnt/sda1/backup_to_restore.tar.gz -a ! -f /mnt/sda1/restore_and_reboot.stop ]; then
	sysupgrade -r /mnt/sda1/backup_to_restore.tar.gz >>/mnt/sda1/restore_and_reboot.log 2>&1
	date >/mnt/sda1/restore_and_reboot.stop
	reboot
fi

exit 0
EOF

(sleep 30 && reboot) &
exit 0

You have to put an USB Key with a backup named backup_to_restore.tar.gz.

The script puts a flag file restore_and_reboot.stop to prevent loop (you have to remove this file to restore again).

Sometimes it does not work because USB Key device is not always here (!?). Switchig USB port helps sometimes (dont ask...). -> SOLVED faulty USB Key (?)

dmesg says /dev/sda1: Can't open blockdev

I tried different USB Keys.

The first one was to recent...

using a old USB key with some king of access led helps a lot.

So the script is working for me.

It's a 2 steps script.

First uci-defaults will inject a rc.local script then reboot (I know it's not very orthodox, but I've put a sleep 30)

Then at boot the rc.local script will try to detect the USB Key with a backup file on it. Restore, put a "Stop loop" flag and reboot.

So the full steps are:

  • build/download the image with the given packages (plus yours) and script
  • write it on a SD Card with balena (or whatever)
  • expand the squashfs partition with cfdisk
  • poweroff the r4s
  • put the usb key with a file named backup_to_restore.tar.gz (remove any file named restore_and_reboot.stop) and the sdcard
  • power on and wait (should reboot twice)

upgraded to stable 23.05 like a charm !

2 minutes downtime top

even my SSH terms stayed alive :stuck_out_tongue:

EDIT: upgrade to 23.05.2

the generator shows the default packages, don't replace but ADD the given list

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