Back Up Raspberry Pi: Full Guide
In this article
To back up a Raspberry Pi, you create a full image of its SD card (or USB drive) and save it to another storage device. This captures the operating system, all settings, and every file, allowing you to restore the entire system by writing that image back to a new card. The most reliable method is to use the dd command on Linux or macOS, or the Win32DiskImager tool on Windows, while the Pi is shut down or the card is mounted read-only.
Why Backing Up a Raspberry Pi Is Different
Unlike a typical desktop PC where you might just copy your documents folder, a Raspberry Pi runs its entire operating system from a microSD card (or USB drive). That card is a single block device containing multiple partitions: a boot partition (FAT32) and a root filesystem (usually ext4). Simply copying files while the system is running can produce a corrupted or inconsistent backup because files change during the copy. A proper backup is a byte-for-byte image of the whole card, which preserves the partition table, bootloader, and all data exactly as they were.
Another reason backups are critical: SD cards are prone to corruption from sudden power loss, and they have a limited number of write cycles. A backup lets you restore a working system in minutes rather than re-flashing the OS and reconfiguring everything from scratch.
Methods for Creating a Backup
There are several ways to back up a Raspberry Pi, each suited to different situations. The most common are:
- Full image with
dd– creates a raw copy of the entire SD card. It is the most complete and reliable method, but it copies unused space too, so the image file is as large as the card (e.g., a 32 GB card yields a ~32 GB image). - Compressed image with
dd+gzip– pipes the output through gzip to shrink the file. This is slower but saves disk space, especially if the card is mostly empty. - Using SD Card Copier (in Raspberry Pi OS desktop) – a GUI tool that clones the current SD card to another card or USB drive. It is easy but requires the destination to be at least as large as the source.
- Using third-party tools like Win32DiskImager (Windows) or
balenaEtcher(read-only) – these can create an image from an SD card on a PC. They are straightforward but require removing the card from the Pi. - Using
rsyncfor file-level backup – copies only files, not the bootloader. This is useful for backing up user data or specific directories, but it cannot restore a bootable system by itself.
Step-by-Step: Backup Using dd (Linux/macOS)
This is the most reliable method and works on any Linux or macOS machine. It requires you to shut down the Pi and remove the SD card, or to boot the Pi from a different card and mount the card you want to back up as read-only.
- Shut down the Pi:
sudo shutdown -h now, then remove the SD card. - Insert the SD card into a card reader on your computer.
- Find the device name: run
lsblkorsudo fdisk -l. It will look like/dev/sdbor/dev/mmcblk0(do not include the partition number, e.g.,/dev/sdb1). - Make sure the card is not mounted:
sudo umount /dev/sdb*(replace sdb with your device). - Create the image:
sudo dd if=/dev/sdb of=~/pi-backup.img bs=4M status=progress - Wait for the command to finish. It will show a progress bar and then return to the prompt.
- Optionally, compress the image:
gzip pi-backup.imgto createpi-backup.img.gz.
Important: Double-check the device name before running dd. If you specify the wrong device (e.g., your main hard drive), you will overwrite it and lose all data.
Step-by-Step: Backup Using Win32DiskImager (Windows)
For Windows users, Win32DiskImager is a popular free tool that can create an image from an SD card.
- Download and install Win32DiskImager from the official SourceForge page.
- Insert the SD card into a card reader on your Windows PC.
- Open Win32DiskImager as Administrator.
- In the “Image File” field, type a name for your backup, e.g.,
pi-backup.img. - In the “Device” dropdown, select the correct SD card (be careful – it shows drive letters, not device names).
- Click “Read” – this reads the card and writes it to the image file.
- Wait for the progress bar to finish. The image file will be the same size as the SD card.
To restore, insert a new SD card, select the image file, and click “Write”. This will overwrite the entire card.
How to Restore a Backup
Restoring is essentially the reverse of creating the backup. You write the image file back to an SD card, overwriting everything on it.
- On Linux/macOS:
sudo dd if=pi-backup.img of=/dev/sdb bs=4M status=progress(replace sdb with your card device). - On Windows: Use Win32DiskImager, select the image, choose the SD card, and click “Write”.
- After writing, eject the card, insert it into the Pi, and boot. The system should come up exactly as it was when the backup was made.
Note that if the backup was compressed (e.g., .img.gz), you need to decompress it first: gunzip pi-backup.img.gz on Linux/macOS, or use a tool like 7-Zip on Windows.
Common Problems and Pitfalls
Several issues can arise when backing up a Raspberry Pi. Here are the most common and how to avoid them:
- Backing up while the Pi is running – This can cause an inconsistent image. Always shut down the Pi and remove the card, or boot from a different card and mount the target read-only.
- Wrong device name in dd – This is the #1 cause of data loss. Always verify with
lsblkand check the size matches your card. - Image file is too large – A 32 GB card produces a 32 GB image. Use gzip to compress, or use a tool like
piclone(on the Pi) that only copies used space. - Card reader not recognized – Some USB card readers have trouble with high-capacity SDXC cards. Try a different reader or a direct SD slot.
- Restoring to a smaller card – The destination card must be at least as large as the source card, otherwise the image won't fit.
Comparing Backup Methods
Choosing the right method depends on your needs. Here’s a quick comparison:
- dd (raw image): Most reliable, complete, but slow and large. Best for full system recovery.
- dd + gzip: Same reliability, smaller file, but slower due to compression. Good for archiving.
- SD Card Copier (GUI): Easy, no command line, but requires a second card and is not suitable for creating an image file on a PC.
- Win32DiskImager: Good for Windows users, but requires removing the card and is not as fast as dd.
- rsync file-level: Only copies files, not the bootloader. Useful for data backup, but not for a bootable clone.
Frequently Asked Questions
Can I back up my Raspberry Pi while it's running?
Technically yes, but it is not recommended. If you use dd on a running system, the filesystem may change during the copy, leading to a corrupted image. You can use tools like rsync to back up files while running, but for a full system image, it’s safer to shut down and remove the card.
How long does it take to back up a Raspberry Pi?
It depends on the card size and speed. A 32 GB card can take 10-30 minutes with dd on a typical USB 3.0 card reader. Using compression adds time. The status=progress option shows the progress and estimated time.
Can I restore a backup to a larger SD card?
Yes, you can restore to a larger card, but the extra space will be unallocated. After restoring, you can use raspi-config to expand the root filesystem to fill the card. The image itself will not automatically resize.
Does the backup include all my files and settings?
Yes, a full image backup captures everything on the SD card, including the operating system, installed software, configuration files, and user data. It is a complete snapshot of the system.
What is the best way to back up just my data, not the whole system?
If you only want to back up user files (like documents, photos, or projects), use rsync to copy specific directories to another drive. For example: rsync -av /home/pi/ /mnt/backup/. This is faster and uses less space than a full image.
Can I use a cloud service to back up my Raspberry Pi?
Yes, you can sync files to cloud services like Nextcloud, Google Drive, or Dropbox using command-line tools. However, these are file-level backups, not full system images. For a complete system backup, you would need to create an image and upload it manually.