There are a number of ways to backup a SD card including Amanda which is popular. I’m sure all of them are good, but I thought I would share my backup system not just the software I use, but also the method and the reasons why, in case you find it useful. I recently found a program called Paragon Hard Disk Manager (PHDM) which is free for home use. There is also an opensource Program called Clonezilla
Edit: Looks like Paragon split the free features into a separate program, called Paragon Backup and Recovery Free, and is currently found here.
The Paragon program is great for two reasons.
- You can restore the image created on a 64gb card back to a smaller 8gb SD card just by ticking a resize box in the program. No need to use the linux program “parted” or “gparted” to resize partitions. More on this topic below…
- It creates images that save space when most of your SD card is empty. Unlike Win32diskimager that creates very large images, PHDM creates a 2gb image for my Openhab backup even when taking a full image of a 128gb card. Larger cards have faster read and write specs.
Clonezilla appears to only do the second feature so would require a partition resize before the backup is made to achieve the first feature.
I wanted to explain why I chose this method and some topics which not all users will be familiar with as this particular method/system is different.
Some things to consider about your backup method are:
- Have a hardware backup as well as a software backup: What happens if your Openhab hardware gets stolen or the hardware physically breaks. Is your backup files stored on that same device? I like the cheap raspberry PIx and SD cards because I wish to always keep a second one around setup ready to go. A full hardware backup ready to go, not just a software backup. Downtime should be able to be fixed in under a minute plus booting time by any family member.
- Never backup a system that has been running a long time: Bit rot, soft error (and many other terms you can google for more info to help you sleep) all work to destroy data over time as computers do make mistakes which then accumulate. Sure you can buy ECC ram, and use methods like parity hard drives to error check creating a ‘better’ servers to run Openhab on, but then the cost of having a HARDWARE backup goes up. The point I am trying to make here is, I do not like to make backups of a system that has been running for any length of time. What is the point of backing up if the files already contain corruption?
- Use a UPS: Dirty shutdowns are when you interrupt the power when the system is running. Never pull the USB plug unless the server is shutdown correctly and also protect your system from this with a UPS. Don’t forget what happens when the UPS runs out of battery life and then the power comes back on and fails in and out. This kind of thing can quickly destroy data on flash based systems as during the boot up period the SD card under goes a lot of WRITES and you never want the power failing when linux is booting as the chance for corruption is very high at that time.
- Learn 1 system that works for all cases: If you use multiple raspberry PIs or Odroid clones for multiple linux projects, this method will work for them all without the need to re-learn how to use Amanda for openhab and FooBackup for this X project. 1 Method works for all and the system is very simple.
- Automatic daily backups should not be relied upon: They can be used in addition to this method to capture small daily config changes, but if they are corrupt and you never use them to find this out, the time when you actually need the backup you will get a big shock.
Now for the details of the backup system
I keep 2 to 3 SD cards which are used for:
- The MASTER card which is setup and then backed up once working. This card lives in the backup hardware PI ready to go, but not running to prevent corruption from accumulating.
- The BACKUP card which is what I use to run my system with and proves the backup file is working.
- An optional TEST card. If I need to experiment or trial a new upgrade (newer is not always better) I put the BACKUP card aside and work with the TEST card whilst I am home, then when I go to work the BACKUP card can go back in until I find some time to continue with the TEST card. Often I find I skip the test card as I can easily make cards from my backup files at any time.
When I need to make a change to my setup, I will load the MASTER card, make the change which I have already tested and then I create a new BACKUP file and card which is then used. The cycle keeps following this process and the MASTER card is never used or left running. Never throw old backup files away.
How to create the Image file:
- Download, install and register the Paragon Hard Disk Manager. It is free for home use if you register.
- Insert your SD card into a usb reader on a windows based machine with above software.
- Follow the wizard step by step to create an Image file of the entire SD card.
- The backup file of my large cards is only taking up 1-2gb on my hard drive because this software does not store every bit that is empty space and compression is used.
How to load/write the Image file onto a smaller SD card:
- Use Paragon Hard Disk Manager as above but follow the wizard to restore the image.
- Tick two boxes, one to resize and the other to change the disks unique ID. This is at the top right corner of one of the restore steps.
- If an attempt fails to work, then the key is to restore the BOOT (first partition) first, and then restore the second partition (larger one) afterwards running the wizard twice to restore only a partition and not the whole disk. By doing this in two steps it prevents the BOOT from being resized and the card should then work. If you don’t use PHDM you can resize the larger partition before taking the image but I recommend taking an image first before playing with the linux program ‘parted/gparted’ to do that.
Why does a restored image not work to an identical SD card with other programs, yet PHDM work fine?
When SD cards (SSD and other flash based storage are the same) are made in the factory, they do quality control testing on the newly made cards and then mark any bad sectors that fail these tests. They get marked in a way so you can not use the failed areas and then they still sell these cards as only a small area of the flash has a minor issue. Because of this you can and probably will have two cards that are meant to be the same, ie same brand, size and model, yet software will tell you they are not the same size.