Network backup/restore script

Hi everyone,

I’d like to start by expressing my sincere gratitude to this forum and especially to frank-w assistance (Profile - frank-w - banana pi single board computer open source project official forum BPI team) for helping me get my BPI-R4 up and running. I’m still learning the ropes and occasionally run into network issues due to my own tinkering.

To address this, I’ve created a simple script for backing up and restoring network configurations. You can find it here: OpenWRT-Tools/firewall_backup.sh at main · fbarcelo2/OpenWRT-Tools · GitHub

Please remember to update the backup location variable according to your system.

I hope this script proves useful to others as well.

Thanks again for all the support!

The menu is even Spanish. :sweat_smile: (or Portuguese?)

Why not use the built-in backup functionality of sysupgrade? Or is it because you wanted explicity just network and firewall?

I used a different approach for my setup and put the whole image configuration in a Github repository. With a build script that uses a container to generate the firmware - sysupgrade image or full SD-card.

Maybe this is something for you as well. I like to have a reproducible image and a single source of truth in case of mistakes made to the running config.

Yes, it’s in Spanish, but if anyone finds it useful, I’ll make an English version.

Edited: Here is the english version OpenWRT-Tools/firewall_backup-eng.sh at main · fbarcelo2/OpenWRT-Tools · GitHub

I was actually “playing” around quite a bit with the firewall because I wanted to set it up so Docker containers could access the internet, but at the same time, not be accessed from the internet—only from the internal network.

To make matters worse, I used iptables out of habit, which led to a mix of iptables and nftables rules. So, eventually, I had to migrate everything.

And every time I messed up, I had to go downstairs (I work on the first floor of my house) and connect locally or even use TTY. To make things even more fun, on a couple of occasions, I managed to knock the internet offline for the entire LAN, which didn’t make my wife (working at my side) too happy :smiley:

That’s why I created a script that allows me to quickly restore just the firewall in a simple and fast way.

Speaking of Docker… as soon as I installed it and spun up a few containers (Cloudflare, etc.), the overlay partition filled up. I uninstalled the containers and changed the Docker configuration to mount it on the NVME drive I installed at /mnt/NVME/opt/docker/, but still, the root system is ridiculously full. The eMMC is much larger than what the root system is using right now, and honestly, this partitioning scheme is kind of confusing, and I’m worried I’ll make a mistake.

I found several guides to expand the filesystem to use the entire eMMC (which, frankly, I don’t understand why it wasn’t sized like that from the beginning), but they’re inconsistent, and I’m not sure which one to follow.

My goal is to use the whole eMMC. In the future, I plan to connect an external HDD via USB, so using a USB stick like some guides suggest isn’t an option for me.

Do you have any suggestions?

root@casabarba:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
mtdblock0 31:0 0 2M 1 disk
mtdblock1 31:1 0 126M 0 disk
mmcblk0 179:0 0 7.3G 0 disk
├─mmcblk0p1 179:1 0 512K 0 part
├─mmcblk0p2 179:2 0 2M 0 part
├─mmcblk0p3 179:3 0 4M 0 part
├─mmcblk0p4 179:4 0 32M 0 part
├─mmcblk0p5 179:5 0 448M 0 part
└─mmcblk0p128 259:0 0 4M 0 part
mmcblk0boot0 179:8 0 4M 1 disk
mmcblk0boot1 179:16 0 4M 1 disk
ubiblock0_4 254:0 0 16.2M 0 disk
fit0 259:1 0 10.7M 1 disk /rom
fitrw 259:2 0 431.9M 0 disk /overlay
nvme0n1 259:3 0 3.6T 0 disk
└─nvme0n1p1 259:4 0 3.6T 0 part /mnt/NVME/opt/docker
/mnt/NVME


root@casabarba:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 10.8M 10.8M 0 100% /rom
tmpfs 1.9G 628.0K 1.9G 0% /tmp
/dev/fitrw 429.9M 426.3M 3.6M 99% /overlay
overlayfs:/overlay 429.9M 426.3M 3.6M 99% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/nvme0n1p1 3.6T 20.9G 3.4T 1% /mnt/NVME
/dev/nvme0n1p1 3.6T 20.9G 3.4T 1% /mnt/NVME/opt/docker
overlay 3.6T 20.9G 3.4T 1% /mnt/NVME/opt/docker/overlay2/28119acec8c9701967949c640c5e994a82e8d6c5ceb5dc5f07f12da75c359691/merged
overlay 3.6T 20.9G 3.4T 1% /mnt/NVME/opt/docker/overlay2/b4b9ae06a946b606ea86dcfa6714ed031f82ca036f66853fcf3be021435e973e/merged

Yes, even though we get off topic here again with that. :sweat_smile:

It’s two steps. Increase the partition size and then update the file system to the new size. I updated mine to 1GB and use the rest for data, in case the nvme is not connected (using some mount magic). There were some recommendations do not make the root partition too big, but I can’t remember why.

Partion changes can be done live. I prefer the the menu driven alternative to parted, but couldn’t find it’s name now. Cfparted or something. Opkg / apk will show you. Then open it and resize the root part.

Afterwards you need to mount the root fs readonly I think. And then upgrade the file system. For me this somehow happened automatically when I flashed the next sysupgrade image via LuCi

Thanks!!

I will try by myself and in case needs some help will create a separate thread!!! :stuck_out_tongue:

Just in case someone lands here by accident looking for how to resize root partition the steps are extremely easy

1 boot on nand
2 install cfdisk opkg install cfdisk or apk add cfdisk if you are on an snapshot
3 cfdisk /dev/mmcblk0
4 expand the partition used as root system (usually p5)
5 write (confirm will require to type yes, not just y)
6 reboot into eMMC and check if everything work (In my case for some reason needed to reboot twice)