Backing up and restoring whole block devices

SD cards are not really a reliable storage, especially when used
constantly e.g. while sitting in always powered-on Raspberry Pi. Because
of that I've recently needed to perform lots of backup/restore
operations ;) I wrote this script for backing up:

Some of the more fun features include progressbars and making sure you've unmounted the
device properly before ;) This also uses parallel threads to deflate the
data, so the XZ compression should not be a bottleneck on any modern
machine. The scripts above were used to backup and restore SD cards but
will work for any block device, be it an external or internal disk
drive, etc. usage example [remember to use the whole device, not just
its partition as an argument]: