Backup your SD cards

It makes sense to backup your SD cards after e.g. successfully setting up you Raspberry Pi. A basic command could look like this:

sudo bash -c "dd if=/dev/sdc bs=1M status=progress | gzip -9 > backup.gz"

If you don’t want to backup the whole disk or your partition is smaller than the SD card, you can also backup only part of the card.

First list the disk geometry:

sudo fdisk -l /dev/sdc
Disk /dev/sdc: 29,28 GiB, 31439454208 bytes, 61405184 sectors
Disk model: STORAGE DEVICE
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x836a2bae

Device Boot Start End Sectors Size Id Type
/dev/sdc1 8192 1056767 1048576 512M c W95 FAT32 (LBA)
/dev/sdc2 1056768 16416767 15360000 7,3G 83 Linux

We backup in blocks of 1M (1024*1024 bytes), so calculate how many blocks we need to read. Multiply the number of sectors used on the disk by the sector size and divide that by the backup block size:

(16416767+1)*512 / (1024*1024) = 8016 blocks of 1M

and use that number as the block count:

sudo bash -c "dd if=/dev/sdc bs=1M count=8016 status=progress | gzip -9 > backup.gz"

Published by HorstBaerbel

Software developer by trade and interest, but I venture into the electronics- and diy-world from time to time.

Leave a comment

Design a site like this with WordPress.com
Get started