How to Back Up a Raspberry Pi: SD Card & NVMe, Even While It Runs
SD cards tend to die without warning, and a botched update can take down a carefully set-up system just as easily. Without a backup, you’re left reinstalling Raspberry Pi OS and rebuilding every service and setting by hand – easily an afternoon gone. This guide shows you how to back up a Raspberry Pi so you can get a working system back in minutes, in most cases without even shutting it down.
Clones, image files and the backup tools work the same whether your Pi boots from an SD card or from an NVMe SSD on a Raspberry Pi 5. We tested them on a Raspberry Pi 5 running Raspberry Pi OS from an NVMe SSD (November 2026).
In short
The fastest way back after a failure is a clone: copy the running system to a second drive with SD Card Copier or rpi-clone, and if disaster strikes, just plug it in.
- Clone: SD Card Copier on the desktop, rpi-clone over SSH – both work while the Pi is running.
- Image file: shrink-backup writes the running system to a bootable .img file that’s only as big as your data.
- Restoring: Raspberry Pi Imager writes any .img back via “Use custom” – but it can’t create backups itself.
Which Backup Is Right for You?
There are three kinds of backup: a bootable clone on a second drive, an image file you write back later, and a plain copy of your files. Which one you want depends on what you need when things go wrong:
| Your situation | Method | What you get | Works while running |
|---|---|---|---|
| Spare drive to swap in, Pi with a desktop | SD Card Copier | bootable clone | yes |
| Spare drive, SSH access only | rpi-clone | bootable clone | yes |
| Keep several snapshots as files | shrink-backup | .img file | yes |
| Pi can be off for a while, you have a PC | Win32 Disk Imager or dd | .img file of the SD card | no |
| Pi 5: 1:1 image of the NVMe SSD | dd after booting from an SD card | .img.gz file | no |
| Regular automatic backups to a NAS | raspiBackup | backup folder with several versions | yes |
| Just your own files and config | rsync with cron | file copy | yes |
Raspberry Pi Imager is missing from that table on purpose: it can only write images to a card, not read them back. For restoring a backup, though, it’s the easiest tool there is. If you can’t decide: a clone on a USB SSD suits most people.
What You’ll Need
- A backup target big enough for everything on your Pi. Check the “Used” column of
df -h /. It doesn’t have to be larger than your system drive. - For clones and images: ideally a USB SSD such as the Samsung T7*. A second microSD card* in a USB card reader* works too, but it’s much slower: our clone to a microSD card took just over an hour.
- For the PC method: a card reader and enough disk space for a file the size of the whole card.
- For rsync: a drive or stick you format as ext4. For raspiBackup: a share on a NAS or a second hard drive.
Bootable Clone While the Pi Is Running
A clone is the quickest backup to recover from: power off, swap the clone in for the original, done. SD Card Copier and rpi-clone copy the running system file by file to the target and adjust the boot configuration so the clone boots on its own.
Before you start: both tools wipe the target completely. Also stop services that write constantly, such as a database with sudo systemctl stop mariadb or Docker containers with docker compose stop in their project folder. Otherwise you may end up with a half-written database in your backup. Start them again once the clone is done, for example with sudo systemctl start mariadb or docker compose start.
With a Desktop: SD Card Copier
SD Card Copier comes with Raspberry Pi OS with desktop and lives in the menu under Accessories → SD Card Copier. Raspberry Pi OS Lite doesn’t include it; you can add it with sudo apt install piclone, but it’s only useful with a graphical desktop.
- Plug in the target, for example your USB SSD.
- Under Copy From Device, pick your system drive: the SD card (
/dev/mmcblk0) or, on a Pi 5, the NVMe SSD (/dev/nvme0n1). - Under Copy To Device, pick the target. The drive the Pi is currently running from never shows up here.
- Tick New Partition UUIDs. Without it, the original and the clone share the same partition IDs, and with both connected, the Pi may mount the wrong partition at boot.
- Click Start and confirm the warning that everything on the target will be erased.

When it’s done, you’ll see “Copy complete.” The clone’s partition IDs are already written into cmdline.txt and /etc/fstab. The target can even be smaller than the original, as long as your data fits.
Over SSH: rpi-clone
rpi-clone is a script that does the same job from the terminal. Bill Wilson’s original hasn’t been maintained since 2020, so use Jeff Geerling’s fork. It handles NVMe drives and the boot partition under /boot/firmware. Installing it takes one line:
curl https://raw.githubusercontent.com/geerlingguy/rpi-clone/master/install | sudo bash
Plug in the target and look up its name. A USB SSD or card reader shows up as sda; a microSD card in the slot of a Pi that boots from NVMe shows up as mmcblk0:
lsblk
Then start the clone. Give just the device name – no /dev/ and no partition number:
sudo rpi-clone sda
rpi-clone shows an overview of source and target and asks Ok to proceed with the clone? (yes/no) – type yes. If the target is empty or formatted differently, it sets up the partitions from scratch and also asks for an optional partition label; just press Enter. At the very end, it waits at Hit Enter when ready to unmount for one more Enter.
Reusing a drive: if the target already has matching partitions, say from an old Raspberry Pi install, rpi-clone doesn’t recreate them – it just syncs the files. To start with a freshly partitioned target, force it with sudo rpi-clone -f sda.
rpi-clone really pays off the next time round: plug the same target back in and it only copies what has changed. With -u it runs without any prompts. On our Pi, a resync took under a minute, while the first clone to a microSD card took more than an hour:
sudo rpi-clone -u sda
The clone gets its own disk ID, and rpi-clone writes it into the clone’s cmdline.txt and /etc/fstab. That way the original and the clone don’t get in each other’s way, even when both are connected.
Network drives: if your Pi automounts network shares and the NAS happens to be unreachable, rpi-clone still reports success – but because rsync plays it safe and stops deleting after a read error, files you’ve deleted since the last clone stay on the clone. So make sure the NAS is up while you clone.
Image File While the Pi Is Running: shrink-backup
If you want to keep several snapshots – one before every big update, say – an image file is handier than a clone. shrink-backup writes the running system to a bootable .img file that’s only as big as your data plus a little headroom, not the size of the whole card.
First, connect an external drive with enough free space. FAT32 won’t do, as it can’t store files larger than 4 GB – exFAT or ext4 are fine. On the desktop, the drive is mounted automatically under /media/, followed by your username and the drive’s label. Without a desktop, mount it yourself as shown in Set Up a USB Hard Drive and Mount It Automatically and adjust the path in the command. As with clones, stop databases and containers that write a lot first.
You’ll need git to download the script. If it isn’t installed yet – on Raspberry Pi OS Lite, for example – install it first:
sudo apt update
sudo apt install git
Then fetch the script and run the backup – here for a drive labelled BACKUP:
git clone https://github.com/UnconnectedBedna/shrink-backup.git
cd shrink-backup
sudo ./shrink-backup -a /media/$USER/BACKUP/pi-$(date +%Y%m%d).img
-a tells shrink-backup to work out the right size itself. The script shows a summary with source, target and estimated image size, then asks Do you want to continue? [y/n]. On our Pi 5 with 45 GB in use, the image came out at 47 GB and took six minutes. shrink-backup skips /mnt and /media automatically, so mounted drives don’t end up in the image.
There’s no need to create a fresh image every time. -U plus the file name of your existing image brings it up to date – for us in a minute. This overwrites the previous state in the image, so copy the file first if you want to keep it:
sudo ./shrink-backup -U /media/$USER/BACKUP/pi-20261101.img
On the first boot after restoring, the system expands to fill the new card and the Pi reboots once. One thing to watch: the image carries the same partition IDs as the original, so don’t connect the restored drive and the original to the same Pi at the same time.
Pi 5 with an NVMe SSD: What’s Different
If your Pi 5 boots from an NVMe SSD, rpi-clone and shrink-backup work exactly the same way: the NVMe is the source, and the target sits on USB or in the SD slot.
To take a 1:1 image of the NVMe while it isn’t in use, boot the Pi from an SD card with a fresh copy of Raspberry Pi OS. Out of the box, the Pi 5 checks the SD card first and boots from it. If you switched to “NVMe/USB Boot” in raspi-config when you moved to NVMe, it will keep booting from the NVMe – in that case, set Advanced Options → Boot Order to “SD Card Boot” for now and switch back afterwards. From the SD card, back up the NVMe to a USB drive. The file has to be written as root too, otherwise the command fails with “Permission denied” on an ext4 drive:
sudo dd if=/dev/nvme0n1 bs=4M status=progress | sudo sh -c "gzip > /media/$USER/BACKUP/nvme-$(date +%Y%m%d).img.gz"
Getting the image back onto the NVMe works the same way round: boot the Pi from the SD card and write the image to /dev/nvme0n1 with gunzip -c and dd, as shown in the restore section. Alternatively, put the SSD in a USB enclosure and write the image on your PC with Raspberry Pi Imager.
Want to move from an SD card to an NVMe SSD rather than back up? That’s covered in Clone a Raspberry Pi SD Card to NVMe.
Imaging the Card on a PC with the Pi Switched Off
If your Pi can be offline for a while, you can also image the whole SD card on a PC. Shut the Pi down with sudo shutdown -h now, take out the card and put it in a card reader on your PC. The image will be as big as the entire card, even if only part of it is in use.
Windows: Win32 Disk Imager
- Install Win32 Disk Imager and launch it with right-click → Run as administrator.
- Under Image File, choose a location and a file name ending in
.img, for examplepi-backup.img. - Under Device, select the SD card’s drive letter. Double-check it in File Explorer so you don’t grab the wrong drive.
- Click Read, not “Write”: Read copies the card into the file, Write would overwrite the card with the file.
Linux: dd
On Linux, find the card with lsblk first. It matches the size of your card and is usually called sdb or mmcblk0. Unmount any of its partitions that are mounted, for example with sudo umount /dev/sdX1 /dev/sdX2. Then dd reads the whole card into a file – replace sdX with your card’s name:
lsblk
sudo dd if=/dev/sdX of=pi-backup-$(date +%Y%m%d).img bs=4M status=progress
You can compress the image with gzip pi-backup-*.img if you like. How much that saves depends on what’s on the card: on a card that’s been in use, even deleted files still take up room in the image.
Backing Up Just Your Files: rsync and cron
If all you care about is your own files and settings, such as /home and /etc, rsync is enough. This isn’t a bootable backup: after a failure, you reinstall Raspberry Pi OS and copy your files back. In return it’s quick, runs in the background and only copies changes after the first run.
The target has to be ext4. USB sticks and hard drives usually come formatted as FAT32 or exFAT. Those file systems know nothing about Linux permissions or symbolic links. rsync throws errors there, and files such as /etc/shadow, which holds the password hashes, end up readable by everyone in the backup – our test run produced more than 2,000 errors. So format the drive as ext4 once. This erases everything on it, so check the device name with lsblk first. If it lists a mount point for the partition – the desktop mounts drives automatically when you plug them in – unmount it first with sudo umount /dev/sda1. Then format it – in both commands, replace sda1 with the name lsblk showed you:
sudo mkfs.ext4 -L BACKUP /dev/sda1
If the drive already has a file system such as FAT32 or exFAT, mkfs.ext4 asks Proceed anyway? (y,N). Type y and press Enter – just pressing Enter cancels and leaves the drive as it was.
To keep the drive in the same place even without a desktop, mount it at /mnt/backup via /etc/fstab. Our guide Set Up a USB Hard Drive and Mount It Automatically shows how.
Next, create a small script:
sudo nano /usr/local/bin/pi-backup.sh
#!/bin/bash
# Back up /home and /etc to the drive mounted at /mnt/backup
TARGET=/mnt/backup
# Stop if the drive is not mounted, otherwise rsync would fill the system drive
if ! mountpoint -q "$TARGET"; then
echo "$(date): $TARGET is not mounted, backup skipped" >&2
exit 1
fi
rsync -a --delete /home/ "$TARGET/home/"
rsync -a --delete /etc/ "$TARGET/etc/"
echo "$(date): backup finished"
The mountpoint check matters: if the drive isn’t mounted, /mnt/backup is just an empty folder on your SD card, and rsync would happily fill it up. Save with Ctrl+O and Enter, exit with Ctrl+X and make the script executable:
sudo chmod +x /usr/local/bin/pi-backup.sh
--delete turns the target into a mirror: anything you delete on the Pi also disappears from the backup on the next run. So it only protects you from accidental deletions until the next run starts. If you need older versions, raspiBackup in the next section is the better fit.
To run the script every night at 3 a.m., open root’s crontab with sudo crontab -e. The first time, crontab asks which editor to use (Select an editor). Press Enter to accept the default, 1, which is nano. Add this line at the bottom:
0 3 * * * /usr/local/bin/pi-backup.sh >> /var/log/pi-backup.log 2>&1
Save with Ctrl+O and Enter, then exit nano with Ctrl+X. There’s more on cron in Setting Up Cron Jobs on the Raspberry Pi. You’ll also find the script and the cron line in our GitHub repository.
Automatic Backups to a NAS: raspiBackup
raspiBackup is the tool for regular full backups: it backs up the running system on a schedule, keeps several versions, deletes old ones automatically and can stop services before the backup starts. You also use raspiBackup itself to restore them.
Mount the target first: raspiBackup saves to /backup by default (you can change the backup path in the installer), but it doesn’t mount anything there itself. So mount your NAS share or hard drive permanently at /backup beforehand – for a network share, for example, through /etc/fstab as described in Mounting a NAS Share on the Raspberry Pi. If nothing is mounted there, raspiBackup stops with error RBK0027E instead of filling up your system partition.
Download the installer from the project site and run it:
curl -sSLO https://raspibackup.linux-tips-and-tricks.de/install
sudo bash ./install
It walks you through a menu where you set the language, backup path, backup type, how many backups to keep and which services to stop. Let the target decide the backup type: for ext4 or an NFS share, pick rsync – every backup after the first then only copies changes. For a Samba share, pick tar, because rsync mode needs links that Samba shares often can’t store (raspiBackup stops with RBK0020E in that case). The installer also sets up a weekly schedule but doesn’t switch it on yet. raspiBackup only sends an email after each backup if a mail program is set up on the Pi.
Exclude network drives: if your Pi mounts other shares under /mnt, leave them out of the backup – otherwise raspiBackup aborts whenever one of them can’t be reached. Open the config with sudo nano /usr/local/etc/raspiBackup.conf and set this line:
DEFAULT_EXCLUDE_LIST="--exclude=/mnt/*"
Vanishing files: if running services delete files during the backup – temporary files, for example – rsync exits with code 24 and raspiBackup aborts the backup (RBK0021E). Either stop those services in the installer or add this line to the same file. It isn’t in there by default, so append it at the bottom:
DEFAULT_RSYNC_IGNORE_ERRORS="24"
Run the first backup by hand so you can see that everything works:
sudo raspiBackup.sh
When it’s done, you’ll see RBK0017I: Backup finished successfully. On our Pi 5 with an NVMe SSD, the first backup in rsync mode took just over six minutes. If everything looks good, switch on the weekly schedule (early on Sunday mornings):
sudo systemctl enable --now raspiBackup.timer
Each backup goes into its own folder under /backup/, named after your Pi. raspiBackup keeps as many versions as you set in the installer, so plan for correspondingly more space than a single backup needs.
Restoring and Testing Your Backup
Clone: switch the Pi off, put the clone in place of the original and switch it back on. If your Pi boots from an SD card and the clone is on a USB SSD, take the card out and plug in the SSD: without an SD card, the Pi boots from USB.
If your Pi 5 runs from an NVMe SSD, it depends on where the clone lives: out of the box, the Pi 5 tries the SD card first, so a clone on microSD boots as soon as the card is in the slot. A clone on a USB SSD only gets its turn after the NVMe. If the NVMe has failed, the Pi falls back to the clone automatically.
To test a USB clone while the NVMe still works, open the bootloader settings with sudo -E rpi-eeprom-config --edit, note down the BOOT_ORDER line and temporarily change it to BOOT_ORDER=0xf14 (USB first, then SD card). Put the old value back after the test. Our BOOT_ORDER generator builds other orders for you.
Image file on Windows, macOS or Linux: Raspberry Pi Imager writes the backup to a new card or to an SSD in a USB enclosure:
- Choose your Raspberry Pi model.
- At the operating system step, scroll down to Use custom and open your backup file. Imager takes compressed
.img.gzfiles as they are – no need to unpack them first. - Pick the target and write. If Imager offers customisation such as a username or Wi-Fi, skip it: your backup already has your settings.
raspiBackup: you restore with raspiBackup itself, onto a drive that isn’t in use. If you only have one Pi, boot it from a second card with a fresh Raspberry Pi OS, install raspiBackup as above, mount your backup target at /backup again and connect the new card or SSD via USB. ls /backup/*/ lists the available backup folders. Then pass the target with -d plus the folder you want. raspiBackup asks “Are you sure? y/N” twice and then overwrites the target completely:
sudo raspiBackup.sh -d /dev/sdX /backup/HOSTNAME/BACKUP_FOLDER
The target can be smaller than the original as long as your data fits: raspiBackup then shrinks the system partition (notice RBK0322I). It assigns new partition IDs and writes them into cmdline.txt and /etc/fstab. When it’s done, you’ll see RBK0076I: Restore finished successfully. In our test, it put 40 GB onto a microSD card in just over an hour.
rsync file copy: reinstall Raspberry Pi OS, mount the backup drive and copy your folders back, for example with sudo rsync -a /mnt/backup/home/ /home/. For settings in /etc, it’s safer to restore just the files you need than to overwrite the whole folder.
Image file on Linux with dd: check the target with lsblk first – dd overwrites whatever drive you give it without asking:
sudo dd if=pi-backup.img of=/dev/sdX bs=4M status=progress
# packed image
gunzip -c pi-backup.img.gz | sudo dd of=/dev/sdX bs=4M status=progress
There’s nothing to fix afterwards: the partition IDs are the same as on the original, so cmdline.txt and /etc/fstab still match. In our test, the restored image was bit-for-bit identical to the original. The flip side: don’t connect the restored card and the original to the same Pi at the same time.
Do a test restore. A backup is only worth something once you know it boots. Restore it to a spare card once, or boot the Pi from your clone while the original is still intact. Then you’ll know exactly what to do when it counts.
Frequently Asked Questions about Raspberry Pi Backups
On the desktop, use the built-in SD Card Copier under Accessories: pick source and target, tick New Partition UUIDs and click Start. Without a desktop, rpi-clone does the same in the terminal with sudo rpi-clone sda. Both create a bootable clone you can swap in if something goes wrong.
Yes. SD Card Copier, rpi-clone, shrink-backup and raspiBackup all back up the running system file by file. Stop services that write constantly, such as databases or Docker containers, first so they end up complete in the backup. Only a full image with dd or Win32 Disk Imager needs the Pi switched off.
No. Raspberry Pi Imager only writes images to a card or SSD; it can’t read them back. It’s ideal for restoring a backup, though: at the operating system step, choose “Use custom” and open your .img or .img.gz file.
An image made with dd or Win32 Disk Imager is as big as the whole card. shrink-backup, rpi-clone and raspiBackup only need as much space as is actually used on the Pi, plus a little headroom. Run df -h / to see how much that is.
Before every major update or change. If your Pi runs around the clock as a server or smart home hub, add an automatic backup as well, such as weekly with raspiBackup or nightly with rsync for your files.
The same way as an SD card: rpi-clone or SD Card Copier clones the running NVMe to a USB SSD or a microSD card, and shrink-backup writes it to an image file. For a 1:1 image, boot the Pi from an SD card and back up the NVMe with dd.
Conclusion
For most people, a clone made with SD Card Copier or rpi-clone on a USB SSD is all it takes – refreshed before every big update. If you want several snapshots, go with shrink-backup; if you’d rather not think about it at all, set up raspiBackup with a NAS as the target. To see how long your current card is likely to last, try our SD card lifespan calculator.
Got questions, or do you back up your Pi a different way? Let us know in the comments!

