Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Backup Raspberry Pi to Synology NAS

· 6 min read · Home Networking

In this article
  1. Why Back Up a Raspberry Pi?
  2. File-Level Backup with rsync
  3. Image-Level Backup with dd
  4. Using Synology Hyper Backup
  5. Choosing Between File and Image Backups
  6. Setting Up SSH Keys for Automation
  7. Common Pitfalls and How to Avoid Them
  8. Frequently Asked Questions

Yes, you can back up a Raspberry Pi to a Synology NAS, and the most reliable method is using rsync over SSH to create a mirror of the Pi's filesystem. This article explains the different approaches, how to set them up, and how to choose the right one for your needs.

Why Back Up a Raspberry Pi?

Raspberry Pi systems are often used for home automation, media servers, network ad-blockers, or development projects. The SD card (or USB drive) that holds the operating system and data can fail without warning, and a corrupted card means reflashing the OS and reconfiguring everything from scratch. A backup to your Synology NAS gives you a restore point that can be brought back quickly, often in under an hour.

There are two main backup philosophies for a Pi: file-level backup (copying files and directories) and image-level backup (creating a bootable snapshot of the entire SD card). Each has its own trade-offs in speed, storage space, and ease of restore.

File-Level Backup with rsync

The most common and efficient method is using rsync, a tool that synchronizes files and directories between two locations. It only transfers changed blocks, so subsequent backups are fast. You run rsync on the Pi, pushing data to the NAS, or on the NAS pulling from the Pi. The latter is often preferred because the NAS can schedule the backup even if the Pi is off (though the Pi must be on for the pull to work).

Here is a typical command run from the Synology NAS (via SSH or a scheduled task) to back up the Pi's home directory:

rsync -avz --delete pi@raspberrypi.local:/home/pi/ /volume1/backups/pi/home/

This copies everything from /home/pi on the Pi to a folder on the NAS, deleting files on the NAS that no longer exist on the Pi. The -a flag preserves permissions and timestamps, -v gives verbose output, and -z compresses data during transfer.

To back up the entire system (excluding virtual filesystems), you would run something like:

rsync -avz --delete --exclude={/proc/*,/sys/*,/dev/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found} pi@raspberrypi.local:/ /volume1/backups/pi/root/

This creates a full mirror of the root filesystem, but it is not bootable by itself—you would need to restore it to a formatted SD card and reinstall the bootloader.

Image-Level Backup with dd

If you want a bootable backup, you can create an image of the entire SD card using dd. This is a low-level copy that captures the partition table, bootloader, and all data. The downside is that it copies the whole card, including empty space, so a 32GB card produces a 32GB image file (unless you compress it).

To create a compressed image directly on the NAS, you would run on the Pi:

sudo dd if=/dev/mmcblk0 bs=4M | ssh user@nas.local "cat > /volume1/backups/pi/backup.img.gz"

This pipes the raw data through SSH and compresses it on the NAS. Restoring is the reverse: decompress and write back to the card.

Image backups are simpler to restore (just write the image to a new card), but they take longer to create and use more storage. They also require the Pi to be shut down or the filesystem to be unmounted to ensure consistency, unless you use a tool like partimage or fsarchiver that can handle mounted filesystems.

Using Synology Hyper Backup

Synology NAS units come with a built-in tool called Hyper Backup, which can back up folders from a remote Linux device via rsync. You can set up a backup task in Hyper Backup that connects to your Pi over SSH and copies specific folders to the NAS. This integrates with Synology's versioning and deduplication, letting you keep multiple versions of files without consuming excessive space.

To use Hyper Backup, you need to enable SSH on the Pi and ensure rsync is installed. On the NAS, create a new backup task, choose “Remote rsync” as the source, enter the Pi's IP address and credentials, and select the folders you want to back up. Hyper Backup will then run the rsync job on a schedule you define.

Choosing Between File and Image Backups

Your choice depends on what you need to restore:

  • File-level backup is best for daily backups of user data, configuration files, and application state. It is fast, space-efficient, and easy to browse on the NAS.
  • Image-level backup is best for a complete disaster recovery, especially if you have a complex setup with many installed packages or custom kernels. It guarantees a bootable copy.

A practical strategy is to do a weekly image backup and a nightly file-level backup. This gives you both granular recovery and a full system snapshot.

Setting Up SSH Keys for Automation

To automate backups without entering a password each time, you should set up SSH key authentication. Generate a key pair on the NAS (or the machine that initiates the backup) and copy the public key to the Pi's ~/.ssh/authorized_keys file. Then rsync or Hyper Backup can connect without a password.

On the NAS, run:

ssh-keygen -t ed25519
ssh-copy-id pi@raspberrypi.local

If ssh-copy-id is not available, manually append the public key to the Pi's authorized_keys file.

Common Pitfalls and How to Avoid Them

Several issues often trip up users when backing up a Pi to a NAS:

  • File permissions: When restoring, files may have wrong ownership. Use rsync -a to preserve permissions, and ensure the restoring user has sudo rights.
  • Excluding virtual filesystems: Forgetting to exclude /proc, /sys, and /dev can cause errors or infinite loops. Always exclude them in rsync commands.
  • Network speed: Over Wi-Fi, backups can be slow. Use Ethernet for the Pi and NAS if possible.
  • SD card corruption: If the Pi is writing to the SD card during backup, the copy may be inconsistent. For image backups, shut down the Pi or use a tool that snapshots the filesystem.
  • Storage space on NAS: A full image of a 32GB card will use 32GB on the NAS. Compress the image or use file-level backup to save space.

Frequently Asked Questions

Can I back up the Pi's SD card to the NAS while the Pi is running?

Yes, you can, but the copy may be slightly inconsistent if files are being written during the backup. For most uses, this is acceptable. For a perfectly consistent image, shut down the Pi and boot from a live system (like a USB stick) to perform the backup.

Does Hyper Backup support Raspberry Pi backups?

Hyper Backup can back up any rsync-compatible device, including a Raspberry Pi. You just need to enable SSH and rsync on the Pi and provide the correct credentials in Hyper Backup.

How long does a backup take?

It depends on the amount of data and network speed. A file-level backup of a few gigabytes over Gigabit Ethernet can take a few minutes. An image backup of a 32GB card can take 10-20 minutes, depending on compression and network speed.

Can I restore a file-level backup to a new SD card?

Yes, but you need to first flash a fresh Raspberry Pi OS image to the card, then boot it and overwrite the system files with your rsync backup. This is more involved than restoring an image backup, but it works.

Is it better to back up to the NAS or to a USB drive?

A NAS offers network access, versioning, and RAID protection. A USB drive is simpler and faster for a single Pi, but it is a single point of failure. For important data, a NAS with redundancy is better.

Can I back up multiple Pis to the same NAS?

Yes, just create separate folders on the NAS for each Pi and set up separate rsync tasks or Hyper Backup jobs. You can even use the same SSH key for all Pis if you copy it to each one.