There are some possibilities to reduce the size of the backup from a SD Card. You can use rsync
as suggested by @binki, or you can use the classic method to do a backup with tar
. With the last one you must mount the ext4 filesystem but macOS doesn't know ext4.
So I suggest another method. You can zero-out the free space on the SD Card. This will not reduce the physical size of the image but it can be compressed very much to nearly the size of the used space for data. There is a pseudo device file /dev/zero
that will output zeros. On a running Raspberry Pi you can copy it to a zerofile as big as the unused space on the SD Card. Of course it will take some time doing it. For an 1.7 GB zerofile I get this:
rpi ~$ time dd if=/dev/zero of=zerofile bs=4M
dd: error writing 'zerofile': No space left on device
434+0 records in
433+0 records out
1817587712 bytes (1.8 GB, 1.7 GiB) copied, 368.33 s, 4.9 MB/s
real 6m43.538s
user 0m0.002s
sys 0m15.563s
As you see the command will terminate with an error when the disk is full. Just delete zerofile
and poweroff the RasPi:
rpi ~$ rm zerofile
rpi ~$ sudo systemctl poweroff
Now you can take a compressed image from the SD Card. Put it into the card reader attached to the laptop. Then assuming it is seen as /dev/sdb
:
# On OS X use lower case 'bs=4m'
laptop ~$ sudo bash -c 'dd if=/dev/sdb bs=4M | gzip > backup.img.gz'
To restore do:
# On OS X use lower case 'bs=4m'
laptop ~$ sudo bash -c 'gzip -cd backup.img.gz | dd of=/dev/sdb bs=4M conv=fsync'
dd
(device dump?) doesn't care about filesystems, so it will copy the whole block device (physical disk or partition) without regards to files folders etc - can MacBook's read ext4 filesystems?-1
?