06 Nov 2015
Thanks to Bill Wilson at https://github.com/billw2
RPI-clone is a shell script that will back up (clone using dd and rsync) a running Raspberry Pi file system to a destination SD card 'sdN' plugged into a Pi USB port (via a USB card reader). Use it to maintain backups of several Pi SD cardsThe SD cards can be a different size (smaller or larger) than the original SD card.
During the clone to new SD cards, rpi-clone provides the opportunity to give a label name to the partition 2 so you can keep track of SD cards.
rpi-clone must be run as root and you must have the rsync program installed.
After rpi-clone is finished with the clone it pauses and asks for confirmation before unmounting the cloned to SD card. This is so you can go look at the clone results or make any custom final adjustments if needed. For example, I have a couple of Raspberry Pis and I use one as a master. When I clone for the benefit of the second Pi, I do a "cd /mnt/clone/etc" and fix the files needed to customize for the second Pi. This can be as simple as loading new hosts and network interfaces file. Just keep all the files on the master:
Download the Bash Script rpi-clone
copy to a more convenient location
$ sudo cp rpi-clone /usr/local/sbin
List all drives
$ sudo fdisk -l
/dev/mmcblk1 is your Raspberry Pi SD operating system (2 partitions)
You are looking for sda devices (samples)
/dev/sda1 is USB 1 (partition 1)
/dev/sda2 is USB 1 (partition 2)
/dev/sdb1 is USB 2 (partition 1)
/dev/sdb2 is USB 2 (partition 2)
/dev/sdc is USB 3 no partitions
$ sudo bash rpi-clone sd? (options)
-v verbose - show all files during copy process
-f force initialization of the destination partitions
-x extreme verbose for debugging
$ sudo bash rpi-clone sda -f
When complete you will be prompted to hit "Enter" when ready to unmount the SD card
WAIT.... Move this window to the side
Recommended to change the Host name so as not to confuse the network
and change to a new hostname for the second Pi.
$ cd /mnt/clone/etc
$ sudo leafpad hostname
$ sudo leafpad hosts
you may now hit "Enter" to unmount the SD card
Error rsnyc: write failed ? - use -f to force partition init and not incremental