A few days ago the Raspberry Pi Foundation announced a couple of cool new features for their desktop UI, one of them being the ability to clone a running Raspberry Pi system to a smaller SD card. The only condition for using a smaller SD-card is that it is big enough to hold all files stored on the original one. In other words only files are copied and empty blocks are never touched. Intrigued I did some background research on how this works as I see a couple of usage scenarios for me if I can replicate this from the command line.
I’m not sure which code they are using but I found this “rpi-clone” shell script on Github by “billw2” that does exactly what I want. It achieves this by only cloning the 50 MB boot partition block by block with the “dd” command while using the rsync file synchronization command for the system partition which occupies the rest of the SD-card. The script can also be used to incrementally copy only files to the backup SD-card that have changed since the last backup. Once rpi-clone is done the backup SD-card is ready to run. Perfect!