OpenWRT and Bare Metal BackUps: Difference between revisions

Line 18: Line 18:
*Overlay "Partition" (only for SquashFS, not relevant to EXT4 based installations)
*Overlay "Partition" (only for SquashFS, not relevant to EXT4 based installations)


====What to do / How to do it / Examples of...====
====What to do / How to do it / Examples of Backing Up / Cloning to an Image File====
Copy the MBR and "MBR Gap" (Choice of doing it in one or two steps, it's also such short process there isn't really a need to add status=progress);
Copy the MBR and "MBR Gap" (Choice of doing it in one or two steps, it's also such short process there isn't really a need to add status=progress);


Line 41: Line 41:
**Working Example: <code>dd if=/dev/sda of=/run/media/root/NTFS/Root.img skip=511 conv=noerror bs=512 status=progress</code>
**Working Example: <code>dd if=/dev/sda of=/run/media/root/NTFS/Root.img skip=511 conv=noerror bs=512 status=progress</code>
*Using CP;
*Using CP;
**cp
**cp -archive --force --verbose Source Destination
**cp -a -f -v Source Destination
**cp -afv Source Destination


...and finally, issue this command, just to make sure everything is flushed from cache / memory: <code>sync</code>
...and finally, issue this command, just to make sure everything is flushed from cache / memory: <code>sync</code>


=== Restoring a BackUp (Image File(s)) ===
===Restoring a BackUp from an Image File(s)===
The reason it is done in separate stages is for demonstration purposes.  And in a recovery situation, it might be that only one "Partition" needs to be recovers.  Plus DD isn't very efficient when it comes to 'empty space'.  Yes, there's that "sparse" option, but it still has to scan / read the entire drive.
The reason it is done in separate stages is for demonstration purposes.  And in a recovery situation, it might be that only one "Partition" needs to be recovers.  Plus DD isn't very efficient when it comes to 'empty space'.  Yes, there's that "sparse" option, but it still has to scan / read the entire drive.
====Assumptions====
In syntax examples, if MBR and "MBR Gap" are cloned in one or two steps, do it the same way on Restoring.
====What to do / How to do it / Examples of Restoring from an Image File====
Copy the MBR and "MBR Gap" (Choice of doing it in one or two steps, it's also such short process there isn't really a need to add status=progress);
*Syntax in one step;
**<code>dd if=/WhatEverPath/WhatEverFileName.img of=/dev/sdX bs=512</code>
*Syntax in two steps (optional);
**MBR: <code>dd if=/WhatEverPath/WhatEverFileName.img of=/dev/sdX bs=512</code>
**"MBR Gap": <code>dd if=/WhatEverPath/WhatEverFileName.img of=/dev/sdX bs=512 seek=1</code>
*Working Example (in one step): <code>dd if=/mnt/sda1/MBR_and_MBR-Gap.img of=/dev/sda conv=noerror bs=512 count=511 status=progress</code>
**Note: Theoretically the count=511 doesn't need to be there because the source file should be the same.  But if one is working from a "whole disk / SSD" backup, that will stop DD's writing at Sector 511, thus not overwriting the first, second, and probably other Partitions.
Copy the Boot Partition (first partition on a 'stock' / 'standard' OpenWRT x86 installation):
*Syntax: <code>dd if=/WhatEverPath/WhatEverFileName.img of=/dev/sdX seek=512 conv=noerror bs=512 status=progress</code>
*Working Example: <code>dd if=/run/media/root/NTFS/Boot.img of=/dev/sda seek=512 conv=noerror bs=512 status=progress</code>
Copy the Root Partition (second partition on a 'stock' / 'standard' OpenWRT x86 installation):
*Using DD;
**Syntax: <code>dd if=/dev/sdX of=/WhatEverPath/WhatEverFileName.img of=/dev/sdX seek=WhatEverOffset conv=noerror bs=512 status=progress</code>
**Working Example: <code>dd if=/dev/sda of=/run/media/root/NTFS/Root.img skip=511 of=/dev/sda seek=34816 conv=noerror bs=512 status=progress</code>
*Using CP;
**cp -archive --force --verbose Source Destination
**cp -a -f -v Source Destination
**cp -afv Source Destination
**Note: If moving a SquashFS based installation of OpenWRT, one can copy the files from the existing SquashFS version of OpenWRT over a standard / initial / virgin installation of OpenWRT, thus 'converting' from SquashFS to EXT4
**Note 2: If doing the process in Note 1, keep in mind that there is also one thing to modify in the /boot/grub/grub.cfg file.  Change this: rootfstype=squashfs To: rootfstype=ext4
...and finally, issue this command, just to make sure everything is flushed from cache / memory: <code>sync</code>


===Syntax Notes===
===Syntax Notes===
Line 63: Line 100:
...and finally, DD seems to be a Zero Based utility, similar to how Disks (and other items like Intel SATA Ports, etc.) are numbered starting from Zero ( 0 ).  So setting skip=511 will skip sectors 0 through 511, for a total of 512 sectors.
...and finally, DD seems to be a Zero Based utility, similar to how Disks (and other items like Intel SATA Ports, etc.) are numbered starting from Zero ( 0 ).  So setting skip=511 will skip sectors 0 through 511, for a total of 512 sectors.


==== CP ====
====CP====


* a: The purpose with this switch in the backup process is to preserve permissions, but the A actually stands for "archive"
*a: The purpose with this switch in the backup process is to preserve permissions, but the A actually stands for "archive"


...and finally, watch out for "Live" versions of Linux, like Rocky Linux, that have an "alias" setup for the cp command (which in the case of Rocky Linux is cp -i, where the -i=interactive).  So what difference does that make?  Well, when you type CP, you're actually typing CP -i.  So if you type CP --force / -f, it won't work as anticipated and you'll end up having to answer yes to every 'overwrite a file situation' (or 'clobber' in the CP venacular).  Why, because the -i switch always trumps the --force / f switch, so the command you're actually typing is CP -i --force / -f, and --force / -f loses to -i.  And the final question of "Why would anyone do that with CP?"  Well, it seems to be done in the name of "safety" (and hair pulling).  And that's a great example of someone trying to think for you.  It is now on this website's Top 3 List of the Most Bone Headed Stupid Things Ever.
...and finally, watch out for "Live" versions of Linux, like Rocky Linux, that have an "alias" setup for the cp command (which in the case of Rocky Linux is cp -i, where the -i=interactive).  So what difference does that make?  Well, when you type CP, you're actually typing CP -i.  So if you type CP --force / -f, it won't work as anticipated and you'll end up having to answer yes to every 'overwrite a file situation' (or 'clobber' in the CP venacular).  Why, because the -i switch always trumps the --force / f switch, so the command you're actually typing is CP -i --force / -f, and --force / -f loses to -i.  And the final question of "Why would anyone do that with CP?"  Well, it seems to be done in the name of "safety" (and hair pulling).  And that's a great example of someone trying to think for you.  It is now on this website's Top 3 List of the Most Bone Headed Stupid Things Ever.