OpenWRT and Backing Up
Rant on Backing Up OpenWRT (Not just the configuration files, but an entire 'Drive' (Flash, SSD, etc.))
How can the entire OpenWRT installation be backed up in a fashion similar to Acronis products, Clonezilla, etc.?
The first answer is that there is no built in facility to do that. Dang! Why not? Well, first of all, OpenWRT is intended to be installed on small router devices where this type of backup (Disk / Drive Imaging, Bare Metal BackUp, etc.) just isn't a thing. Second, and largely because of something mentioned in the first item, is that a program like that can't be crammed into a small enough space to fit on small router device.
Spoiler Alert: RESTIC
What about Baquacil, err, wait, that's a pool chemical. Bactine! No, that's the antiseptic. RESTIC! Yup, that's the utility for backing up in OpenWRT (the only one)
Sadly it's like EDLIN VS Microsoft Word. No offense to the nice RETIC people. It does it's job and works reliably. But seems as if was made in the 1980s (it was actually done in the 20 teens). Again, no offense, it has a ton of features and seems bullet proof.
And most of all, RESTIC is for backing up files on a Disk, Volume, or Partition. It is not capable of (nor is it intended for) backing up an entire disk or partition, including boot sectors, file tables, etc. It is not a Disk / SSD or Partition Imaging device.
Wah! But what if I want to do it anyway because... Well, because I want to
Other Choices
Clonezilla? Yup, great, but one issue. One has to boot from the Clonezilla CD / DVD / USB Flash Drive / ISO to do it. Router off, Clonezilla on.
Again; WAH! I want to do it with the Router still fully functional, IE from within OpenWRT.
What About DD?
Perfect! Except for one thing: Files might change right in the middle of a backup (because it takes a long time). Remember DD has no capability or concept of "Volume Shadow Copy" (Note: RESTIC doesn't have the capability, but it does have the concept of it, however that would require converting the entire OpenWRT install over to an LVM based Disk / SSD / Whatever 'Layout'.)
Ideal Objective
Ideally, the only solution would seem to be something like Acronis for Linux (or some other commercial product). Or something like RUBackUp and / or FSArchiver. The latter requiring the above noted conversion of OpenWRT over to an LVM based Disk / SSD / FlashDrive system. That's a lot of work. The best option would be making DD aware of Volume Snapshots and doing it that way. Ongoing work with this experiment will be to attempt changing the disk layout to include an LVM volume that allows for "Volume Shadow Copy" (Volume Snapshot, etc., IE, the Linux equivalent of that Windows feature) and using DD for a Bare Metal BackUp!
Cop Out, err, Respect!
Please remember, none of this is rant is intended to be disrespectful to the OpenWRT, RESTIC, or anyone else that might have felt slighted. It is simply a colorful way of noting how in the software world, once someone is given something, the inevitable question and desire of 'What else can it do?" comes up. That's what this is about
DD as the Chosen Solution
Back It Up
To make sure the Image is as small as possible: dd if=/dev/zero bs=1M conv=noerror,sync status=progress of=/overlay/ZeroByteFile (this will fill all unused areas of the Disk / SSD / USB Flash Drive / etc. with Zeros)
dd if=/dev/WhatEverSDx of=/mnt/WhatEverSDx/WhatEverImageName.img conv=sync,noerror bs=64K status=progress (Example: dd if=/dev/sdb of=/mnt/sda1/ALL.img conv=noerror,sparse bs=1M status=progress)
Remember, using DD to clone /dev/WhatEverSDx is not enough. There's also the /overlay Directory / Loop Device to consider.
Create a "Device" to Mount, IE Associate a File with a Loop Device Node
losetup -fP WhatEverImageName.img (To see mounted "Devices": losetup -a), (f = File Name to configure as a Loop Device, P = Scan Partition Size, a = Show All Loop Devices, b = sector size)
"Man" Page for LOSETUP: https://man7.org/linux/man-pages/man8/losetup.8.html
Loop Device: https://en.wikipedia.org/wiki/Loop_device
Mount the Image
mount -t squashfs /dev/loop7 /mnt/squash
Keep in mind this only works with IMG Files created from Partitions. If an entire disk drive is imaged, the above method won't work. However...
Mount an Image of an Entire Disk
If an entire disk is imaged with DD, then a "map" of it can be viewed with CFDISK: cfdisk /dev/WhatEverLoopDevice (Example: cfdisk /dev/loop5) (Remember, use losetup -a to see "Devices")
Examining the output of CFDISK will show the names of the individual Partitions available: /dev/WhatEverLoopDevicePx (Example: /dev/loop6p1).
With the above information garnered from CFDISK, then mount individual Partitions: mount -t WhatEverFileSystem (squashfs, ext4, ntfs-3g, etc.) /dev/WhatEverLoopDevice /mnt/WhatEverMountPoint: mount -t squashfs /dev/loop6p2 /mnt/Loop6/p2 (Also: losetup -d /dev/WhatEverLoopDevice will delete the loop device)
Note on: LOSETUP -d WhatEverLoopDeviceName
Bad news. The delete command doesn't always work. After issuing the command on a legitimate Loop Device, and with no errors, the Loop Device will persist. Checking it with LOSETUP -a shows it is still there. Accessing it with CFDISK or MOUNT still works. Oh, well. Windows solution time. Reboot.
And More...
What about taking that RAW Image created by DD and turning it into a VHD File (or just about any other virtual disk format)