Creating a bootable SD card clone for use as backup

I'm really looking for something simple that can be done while Pi-hole is running, and was thinking of using a USB SD card reader/writer. I have found two possible options:

  1. "SD Card Copier", from the Raspberry Pi Desktop's Accessories menu, which I would use via VNC, or
  2. "rpi-clone" - GitHub - billw2/rpi-clone: A shell script to clone a booted disk. - via SSH, using PuTTY

I was particularly wondering how large the risk was of getting an inconsistent set of files was, and if necessary how to mitigate that risk. Apart from the software mentioned above, there should be nothing I am aware of running - but there may be stuff in the background?

Also, any pros and cons of the two methods mentioned above, and other thoughts that may spring to mind, would be welcome.

Well, from extremely limited experience, I can confirm that my "method 1" works - I can create a bootable disk with a working Pi-hole.

But I'd still appreciate hearing from other people :slight_smile:

On my Pi, the disk/SD card is called mmcblk0 with two partitions mmcblk0p1 and mmcblk0p2:

pi@ph5:~ $ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 14.9G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 14.6G  0 part /

pi@ph5:~ $ sudo parted -l /dev/mmcblk0
Model: SD SU16G (sd/mmc)
Disk /dev/mmcblk0: 15.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  273MB   268MB   primary  fat32        lba
 2      273MB   15.9GB  15.7GB  primary  ext4

If want to create a disk image live, you can run below command.
But the backup path below (the of= argument) cant reside on the same SD card or the disk would run full.
Need to write the backup image to a larger mounted NFS or CIFS share.
Or maybe to a connected USB stick or HDD.

sudo dd status=progress conv=noerror,sync if=/dev/mmcblk0 of='/mnt/path/to/backup/location/pi.hole.img'

Shrink and gzip the resulting image pi.hole.img with below for archiving (thanks to Bucking_Horn for the link):

Ow ps. if connect the card reader to the Pi and insert backup SD card, you can use the same dd tool to create a 1 on 1 copy:

sudo dd status=progress conv=noerror,sync if=/dev/mmcblk0 of=/dev/sda

But first run lsblk before and after inserting the backup SD card to validate the card is assigned the name sda from above command (change if other).
Also check with lsblk first if any partitions from that sda block device were automatically mounted (the MOUNTPOINT column).
Unmount them first before start copying with below:

sudo umount /path/to/mountpoint

And check with lsblk again if anything still mounted from sda.

And when copying is finished and want to pull that backup SD card, run below first for safety:

sync

I wasnt reading your initial request properly when first replying as I was distracted :smiley:

Thank you @deHakkelaar.

In the sense of coping with possible changes to various files during the copying process, are those methods more likely to succeed than the two methods I mentioned? Or are any pros/cons mainly about how you want to organise backups?

(I am beginning to sense that there is only a negligible chance of not being able to successfully get a working system from a backup, so maybe I need not worry too much.)

I dont know what UI your talking about as I dont have a desktop :slight_smile:
And am unfamiliar with the second rpi-clone option.

The dd and lsblk commands etc are readily available on most distros.

EDIT: Be careful though with the dd command !
Its got the nick name "disk destroyer" if just make a tiny mistake and wipe a disk useless :wink:

I guess it is unimportant to you then, but I have anyway edited the top post to be more specific about the UI

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.