sudo fdisk -l
Take note of how the SD card is identified.
In my case it is /dev/sdb1.
Then:
sudo dd bs=4M if=/dev/sdb | gzip > /home/your_username/image`date +%d%m%y`.gz
This will compress the image using gzip.
To restore the backup on SD card:
sudo gzip -dc /home/your_username/image.gz | sudo dd bs=4M of=/dev/sdb