How to Back Up Your Raspberry Pi

by Tyrese Harris
16 minutes read

How to Back Up Your Raspberry Pi

Raspberry Pi Rsync Ago-up

Endorsing upward your Raspberry Pi doesn’t have to be made complex. While there are multiple refined recommend-up takes care of obtainable, occasionally the most convenient philosophy is the most beneficial. In this article, I’ll underline you how to application rsync – a tiny but mighty command-pitch gadget that’s supreme for creating dependable urban recommend-ups of your Raspberry Pi arrangement.

Content
  • Why Rsync Is The Faultless Gizmo For Endorsing Upwards Your Pi
  • Using Rsync to Ago Upwards Raspberry Pi Documents and also Folders
  • Wreaking Full Raspberry Pi Fallbacks Using Rsync
  • Regaining Your Rsync Raspberry Pi Fallbacks

Why Rsync Is The Faultless Gizmo For Endorsing Upwards Your Pi

Rsync (confidential sync) is a beneficial document synchronization and also send gadget that comes pre-mounted on your Raspberry Pi.

At its core, rsync optimally photocopies records from one locale to an additional, but it’s a jumble wiser than a humble photocopy operation. It singular transfers the parts of records that have switched over, saving both time and also gadget resources. This is especially valuable as shortly as stabilize upward considerable records that readjust occasionally.

Male Rsync Raspberry

I on the entirety application rsync to recommend upward my disturbingly valuable user file on the Pi. For instance, I preserve a pic gallery internet server on my Raspberry Pi, and also rsync is supreme for proving a recommend-up photocopy of with one voice those valuable images on an outside drive, with brand name-gimmicky or revised records quickly detected and also copied.

Unlike tools recommend-up that photocopy entire records, rsync singular transfers switched over sectors, obtaining recommend-ups markedly quicker and also undervaluing wear on your SD card. Its command-pitch user interface conducts it supreme for automation with cron jobs, while designed-in checksumming ensures recommend-up renown. Faultless of with one voice, rsync’s lightweight nature averages it won’t retard your Pi unless a recommend-up process is currently running, nor will most certainly it collar upward too a jumble SD card storage place.

For these justifications, rsync is the safest cure for my last bargains, and also I think it’s an optimum selection for multiple polymorphous other Raspberry Pi audiences that twinge a dependable, fertile recommend-up gadget.

Using Rsync to Ago Upwards Raspberry Pi Documents and also Folders

The most convenient means to recommend upward a catalog is with the command:

rsync -av /source/directory /backup/location

For instance, to recommend upward my abode catalog to an outside drive mounted at “/media/recommend-up”, I application the command:

rsync -av --delete /home/david/immich-app /media/backup

to recommend upward my pic library file source.

Rsync Raspberry Folder Ago-up

Here’s what the dissimilar wills do:

  • -a permits archive mode, which maintains document authorizations, domestic, and also timestamps
  • -v lends verbose output so I can go to what’s being copied.
  • --delete clears records from the recommend-up locale that no longer exist in the source.

Note: You need to correspondingly realize that rsync is choosy about trailing slashes in courses. A trailing ameliorate on the source averages “photocopy the contents of this catalog” rather than the catalog itself. For instance, rsync -av --delete /home/pi/folder /media/backup photocopies the contents of ‘folder’ uncolored relevant into ‘recommend-up’, while vacating out the ameliorate photocopies the ‘folder’ catalog itself relevant into ‘recommend-up’.

Reflect Your Raspberry Pi Ago-up

In yesteryear counting on your recommend-up, you need to validate that it massaged correctly. The most convenient means to check is obtaining application of the dry run substitute with rsync, which can be classified as either -n or --dry-run. Running the command:

rsync -avn --delete /home/pi/folder /media/backup

need to underline no records terming for to be sent if your recommend-up is upward-to-date.

Rsync Raspberry Ago-up Dry Sprinted

For a more attentive verification, you can add the -c or --checksum substitute to your rsync command. While slower than the default timestamp and also size comparison, this assures that every document is faultlessly attire between source and also recommend-up by scheming checksums. Merely run:

rsync -avc --delete /home/pi/folder /media/backup

The most labelled means to validate your recommend-up is obtaining application of the diff command, which compares every document and also catalog between your source and also recommend-up stainings. To lug out this verification, application:

diff -r /home/pi/folder /media/backup/folder

The -r substitute notifies diff to check with one voice subdirectories recursively. If the command devises no output, it averages your recommend-up is attire to the source. If there are differences, diff will most certainly underline you specifically which records are dissimilar or absent.

Wreaking Full Raspberry Pi Fallbacks Using Rsync

In some predicaments, it can be more achievable and also more secure to recommend upward your entire Raspberry Pi SD card instead of simply a handful of disturbingly valuable folders.

To design full Raspberry Pi recommend-ups obtaining application of rsync, you’ll last prearrangement a recommend-up location – either an additional SD card or an outside drive with enough enclosure to grasp your entire gadget. The recommend-up drive need to be formatted with a Linux-commensurate filesystem like ext4 to preserve with one voice document authorizations and also services correctly.

The trickiest portion of stabilize upward a full Raspberry Pi gadget is taking care of momentous gadget magazines and also records correctly. In my withstand, the most convenient cure is to exclude gadget magazines that either worn’t have to be recommended upward or can induce anxiety if regained. Invent a document labelled “recommend-up-exclude.txt” and also add the cooperating with gadget magazines that need to be left out from the recommend-up:

  • /proc/* # Runtime process niceties
  • /sys/* # Kernel and also gadget niceties
  • /dev/* # Machine records
  • /tmp/* # Temporary records
  • /run/* # Runtime file
  • /mnt/* # Space variables
  • /media/* # Removable media
  • /abode/pi/.cache/* # Audience cache records
  • /thrown away+identified # Filesystem recuperation catalog

Using these exemptions in void, you can comfy as multiple running executions as you can and also then execute the cooperating with recommend-up command:

sudo rsync -avxhP --delete --exclude-from=/home/pi/backup-exclude.txt / /media/backup/rootfs/

The -x substitute inhibits rsync from going across filesystem perimeters, which can induce priorities with gadget magazines. The -h substitute conducts rsync underline document measurements and also send prices in a human-readable layout.

Automating rsync recommend-ups

While manually invented full recommend-ups are valuable, I like to automate them obtaining application of Linux’s designed-in cron scheduler. To classified this upward, design a document labelled “recommend-up-pi.sh” in your abode catalog with this content:

#!/bin/bash BACKUP_DRIVE="/media/backup" LOG_FILE="/home/pi/backup-log.txt"   # Check if backup drive is mounted if ! mountpoint -q $BACKUP_DRIVE; then     echo "Backup drive not mounted at $BACKUP_DRIVE" >> $LOG_FILE     exit 1 fi   # Create timestamp for logging date >> $LOG_FILE   # Run backup with error checking sudo rsync -avxhP --delete      --exclude-from=/home/pi/backup-exclude.txt      / $BACKUP_DRIVE/rootfs/      >> $LOG_FILE 2>&1   # Record backup completion echo "Backup finished at $(date)" >> $LOG_FILE echo "-------------------" >> $LOG_FILE

Gain the script executable with chmod +x backup-pi.sh, then practice it obtaining application of cron. Kind crontab -e and also add this pitch to run the recommend-up day-to-day at midnight:

0 0 * * * /home/pi/backup-pi.sh
Cron Raspberry Ago-up

Regaining Your Rsync Raspberry Pi Fallbacks

For retrieving person records or magazines, the process is uncomplicated. Simply swap the source and also location in your rsync command. For instance, to regain your pic library from recommend-up:

rsync -av /media/backup/home/david/immich-app/ /home/david/immich-app/

For a full gadget remodelling, you’ll last prearrangement a fresh setup of Raspberry Pi OS on your SD card initially. Overture by mounting a fresh photocopy of Raspberry Pi OS on your brand name-gimmicky SD card. As shortly as that’s performed, boot your Pi with the brand name-gimmicky SD card and also wrap up the initially arrangement process. Next, attach your recommend-up drive to your Pi. As shortly as every little thing is hooked and also mounted satisfactorily, you can regain your recommend-up obtaining application of the rsync command:

sudo rsync -avxhP /media/backup/rootfs/ /

After remodelling is wrap up, I suggest rebooting your Pi to check if with one voice regained records are satisfactorily loaded. You need to correspondingly validate that your disturbingly valuable takes care of and also arrangements are cleaning as intended.

If particular executions aren’t cleaning after remodelling, check their log records (occasionally in /var/log/) for any kind of permission-related missteps. You can have to run:

sudo chown -R $USER:$USER /home/$USER

to mend domestic of your abode catalog records. As you can go to, retrieving with rsync is as inalienable as creating recommend-ups – simply overturn the source and also location courses in your commands.

While I like rsync’s command-pitch ease, there are multiple unblemished GUI wills if you’re not comfy with the terminal. For instance, Syncthing permits you to synchronize innumerable folders throughout dissimilar tools, while Timeshift delivers gadget snapshot application with a spotless user interface. Whichever gadget you opt, the disturbingly valuable thing is to preserve steady recommend-ups of your Raspberry Pi to secure your valuable file and also gadget arrangements.

Unanimously images by David Morelo.

Related Posts