Raspberry Pi - How To Backup or Clone SD Card
It is a good idea to backup your Raspberry Pi’s SD card. There are two main options to do this and there are different variations of these options. The first option is to backup to a second SD card directly from the Pi. The second option is to back it up to an image file from a separate system.
Clone the SD Card to Another Card from the Raspberry Pi
You can clone your SD card directly from your Raspberry Pi while it is running. You just connect another SD card and use the SD card copier application that comes with Raspberry Pi OS. This should work with both NOOBS and Raspberry Pi OS images. This will backup your entire system.
The destination card can be larger or smaller than the current system card so long as there is enough space on the card to fit all files. If there isn’t enough space you will receive a warning.
WARNING - This will wipe all data on the destination card.
Raspberry Pi SD Card Backup Steps:
- Put a new SD card in a card writer.
- Connect the card writer to your Raspberry Pi.
- Start the “SD Card Copier” application ( under Accessories on the start menu ).
- Select your internal SD card under “Copy From Device”.
- Select the card in the writer as the “To Device”.
- Hit “Start”. It may take 10 to 15 minutes to complete.
- Once complete you can now use the new card to boot the system or to boot another system.
Clone the SD Card to an Image File
You can also clone your SD card to an image file. This is great for a few reasons:
- Easy to keep multiple backups
- Can restore from an image file
- Can restore/clone to a different SD card
- Can store on reliable, efficient, large scale storage ( like a NAS )
- Can be compressed to save space
These instructions should work from a Mac or from Linux. A Mac will use 4m instead of 4M.
Backup SD card to image:
sudo dd bs=4M if=/dev/sdb of=backup1.img
Restore image to SD card:
sudo dd bs=4M if=backup1.img of=/dev/sdb
Backup SD card to compressed image:
sudo dd bs=4M if=/dev/sdb | gzip > backup1.img.gz
Restore compressed image to SD card:
gunzip --stdout backup1.img.gz | sudo dd bs=4M of=/dev/sdb