If you want to back up the Raspberry Pi SD card, you cannot simply plug the SD Card into your Mac or PC and copy all the files to your hard drive. Instead, you need to create what it is called disk image. This is because, when you create a disk image of your SD card, you will preserve not only all the files but also the entire filesystem structure.
Therefore, once you decide to flash a new SD card, you just have to plug it in and it will work.
Firstly, insert the SD card into a USB card reader of your Mac and open the Terminal and type the following command in order to list all the disks attached to your Mac:
From the list, identify which /dev/disk corresponds to the SD card.
Now just use the dd command to backup of your SD card:
dd if=/dev/rdiskx of=/path/to/image.img bs=1m
where /dev/rdiskx is your SD card and /path/to/image is the path where you want to save the backup. The backup image will be a file .img.
However, it is also possible to create a compressed SD card image (.gz) as follows:
sudo dd if=/dev/rdisk1 bs=1m | gzip > /path/to/backup.gz
To restore an SD card from a backup image, use the following command:
sudo dd if=/path/to/image.img of=/dev/rdisk1 bs=1m
On Linux, similar to Mac, you can use the standard dd tool:
dd if=/dev/sdx of=/path/to/image.img bs=1M
Where /dev/sdx is your SD card.
To create a compressed SD card image use the following command:
sudo dd if=/dev/rdisk1 bs=1M | gzip > /path/to/backup.gz
To restore an SD card from a backup image (.img):
sudo dd if=/path/to/image.img of=/dev/rdisk1 bs=1M
On Windows, you can use Win32 Disk Imager. The following screen-shoot is the main window.
Firstly you need to select which drive is your SD card. In this case my SD card is F:\.
Then, click on the blue icon just next to the F:\ to open a file-explorer window. Here you have to select where you want to save the image file and the type of image (.img, .bin, etc..).
You have to confirm the folder and filename are correct. When ready just click the Read button. When completed it will show Done!
To restore the SD card from a backup image, just follow the same process but this time click the Write button.