This article shows a method, using Linux,  to save SD content to an image, and restore the image to another SD, useful to create some backups, to copy SD to another one (even if disk sizes are different) and restore backups to SD.

Do you want to keep a backup of your system running in a microSD, and have the ability to restore it to another SD?

Clone a microSD to another one, even if memory size is higher or lower?

The following script runs in a Linux environment, using the fsarchiver program to create image from a disk (even if it has many partitions) while operating system is running (it's not 100% reliable like a snapshot, but most probably it works correctly).

For example, the first domotic system I installed on a Raspberry PI3 with Raspbian (Debian Linux) and Domoticz stopped working properly after almost 5 years due to MicroSD corruption  (it used a SanDisk Ultra 16GB memory card). As the system was equipped with a automatic backup (written to an external USB disk) that also create disk images using fsarchiver, it was very easy and quick to take the nightly disk image and create a new MicroSD (64GB SanDisk High-Endurance).

Home automation system images with Domoticz

We have prepared some images that are ready to use and optimized to preserve flash memory, limiting writings to it. Also, they are already equipped with firewall, backup system and many useful tools.

They can be installed in any flash memory with at least 4 GB space. Flash memory high-endurance type is recommended!

Why Domoticz?

If you want to use Alexa to turn on a light and do some zapping on the smart TV, maybe Domoticz is not the best solution.
But if you want to have a very stable, lightweight and reliable home automation to control alarm sensors, climate, lights, load balancing and power management when photovoltaic is installed, Domoticz is certainly one of the best systems.
It's a free open-source software, written in C++ (not Java or Python or other inefficient languages), it does not need huge resources (works well with 256MB of RAM); it supports many scripting languages to make automations; it has not a nice user interface, but is very reliable: if you don't want that your wife comes home finding that lights does not work and house is cold (in the Winter), maybe you have to consider Domoticz software! Click to see Domoticz in a high-automated house with hundreds of devices.

Installing a Raspberry PI3 / PI4 image with Raspbian and Domoticz

Raspberry PI 4 is a popular single board computer 512 MB of RAM or more, and with 2.3W power consumption.

From a Linux terminal (you should connect to Linux computer by using a SSH client), type the following commands (I assume that you're using a Debian-like distribution):

# become root
sudo su -
# install curl and fsarchiver, if needed
apt update
apt -y install curl fsarchiver
# download the image creation/restore script
curl -o /usr/local/sbin/raspberry_domoticz.sh http://dl.creasol.it/raspberry_domoticz.sh

chmod 700 /usr/local/sbin/raspberry_domoticz.sh
#donwload the image
cd /
curl -o /raspberry_domoticz_0x12345678.fsa http://dl.creasol.it/raspberry_domoticz_0x12345678.fsa
#and now start the raspberry_domoticz.sh script
raspberry_domoticz.sh

then the raspberry_domoticz.sh script will guide you to write the image /raspberry_domoticz_0x12345678.fsa on a microSD connected to domoticz by a SD memory USB reader.

This is the output of raspberry_domoticz.sh script, in bold the text written by the user:

Would you like to create an image of the SD [SD => IMAGE] (Y/n/ctrl-c)

n   (no, don't need to create an image, I need to extract an image!)

Would you like to write an image to new SD [IMAGE => SD] (Y/n/ctrl-c)

y   (yes! extract an image to SD)

========== List of attached devices: ==========
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 1.9G 0 disk
`-sda1 8:1 1 1.9G 0 part
mmcblk0 179:0 0 58.3G 0 disk
|-mmcblk0p1 179:1 0 400M 0 part /boot
|-mmcblk0p2 179:2 0 4.9G 0 part /
`-mmcblk0p3 179:3 0 24.4G 0 part
Write the name of USB device where image have been placed (for example sda1)

mmcblk0p2  (write the name of device corresponding with root filesystem, where the image was downloaded, or the device containing the image, for example a usb drive)

========== List of files in the selected device ==========
total 508712
....
-rwxr-xr-x 1 root root 520823743 Feb 26 17:39 raspberry_domoticz_0x12345678.fsa
drwx------ 4 root root 4096 Feb 26 17:37 root
...
Write the image filename

raspberry_domoticz_0x12345678.fsa

========== List of attached devices: ==========
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 31.1G 0 disk
`-sda1 8:1 1 31.1G 0 part
mmcblk0 179:0 0 58.3G 0 disk
|-mmcblk0p1 179:1 0 400M 0 part /boot
|-mmcblk0p2 179:2 0 4.9G 0 part /mnt/img
`-mmcblk0p3 179:3 0 24.4G 0 part
Write the name of FLASH device to be written (example sdb)

sda  (disk device connected to raspberry or PC, with the microSD card)

If you want to translate texts of raspberry_domoticz.sh in a different language, just modify the script adding the corresponding lines text[LANG,NUMBER] : it's very intuitive. Please send to This email address is being protected from spambots. You need JavaScript enabled to view it. the modified script and your name, so we can publish your improvements.

Installing a Rock Pi S image with Linux and Domoticz

Rock Pi S is a tiny single board computer with 512 MB of RAM and only 0.4W power consumption. As Domoticz is written in C++, it works very well with this SBC in case that only few scripts are used. If many many long scripts are needed, it's better to use a more powerful hardware, like Raspberry PI 4.

To put a Rock PI S image of Linux + Domoticz on a microSD, follow the same procedure used for the Raspberry (see the section above) but downloading the image file 

http://dl.creasol.it/raspberry_domoticz_0x12345678.fsa

instead of

http://dl.creasol.it/raspberry_domoticz_0x12345678.fsa

Creating an image of a microSD (microSD => image file)

ToDo

Restoring a saved image to another microSD (image file => microSD)

ToDo