2

I have started using the rsync tool to backup data from Raspberry Pi's SD card. The command I use is:

sudo rsync -aAHXv --delete --exclude-from=/home/pi/rsync-exclude.txt / /media/pi/PI_BACKUP/

based on the excellent stackexchange post by @goldilocks here.

I can see that rsync clones the directory structure on my SD card. When it comes to restoring from the backup, I have a few points that I struggle with and seek clarity upon.

  1. Restoring a file or directory is the part that I am most comfortable with. I can use the rysnc tool to backup and restore my work (documents, images, scripts, etc.) without a problem. But will it work to restore installed software?
  2. I have software like GNU Radio installed from the software repository with the built-in package manager on Raspbian (Buster). This software is time-consuming to install. I have read that "everything is a file in Linux ." Further, I have read that the built-in package manager will add files in a standard location, such as /usr/lib or /opt. Does this mean that including these folders in the back-up copy of the root file-system is sufficient by itself to restore the software in the event of corruption (without the need for reinstallation)?
  3. Some of the software is installed outside of the package manager. For example, I have Arduino IDE installed. Since everything is a file in Linux, will this software also be reinstalled simply by including the folders where software is installed in the back-up copy of the root file-system?

There is also this solution proposed in a linux journal that appears to suggest the entire system can be backed-up and restored with rsync. I struggle to understand how this will work in practice with Raspberry Pi. My interpretation is when the Pi's SD card gets corrupted, do the following:

  • Boot the Pi from a USB stick (not supported by all models of Pi.)
  • Mount the (corrupt) SD card and the back-up medium.
  • Restore the root folder with all its contents from the back-up medium to the original SD card with rysnc.

And presto! The corrupted card springs back to life as if nothing happened, all software and data intact. Is my understanding correct? What if the original is damaged beyond redemption? I am a beginner at best when it comes to linux and grateful for any help.

1 Answer 1

2

Rsync is a great tool if you need to create a backup of some files/directories - in particular if many large files need to be backed up that rarely change (rsync will only transfer the ones that changed). Technically you're right, most things in Linux are stored on the filesystem. A backup (if done correctly) will allow you to restore the installed software, your configuration, device nodes in /dev/ etc. There are a few potential pitfalls, though:

  1. Files will be copied one-by-one so in cases where multiple files belong together they might end up out-of-sync. Example: You are running a photo gallery on your Raspi and while the backup is underway a user imports new pictures which results in the pictures being written to the filesystem and some entries being written to a separate database file. If your directory with the pictures happens to be copied at the very beginning of your backup and the database at the end you might end up with a backup that has a database containing the new pictures but is missing the corresponding images. It depends on the nature of your software if this might cause major headaches.

  2. Some software doesn't guarantee that files on the disk are always in a consistent state. In other words if you backup a file while it is being edited you might have backed up a corrupted file. Most likely you'll be fine but it's safer to close all files - for the operating system that means shutting it down. If you don't do that your mileage my vary.

  3. You have to make sure your backup works correctly for all the funny "file" types a Linux system uses. For example you might want to pay attention to device nodes in /dev/, and pseudo-filesystems in /proc/ and /sys/ and files required during the boot process. Try restoring to a fresh SD card to verify your backup is working correctly.

  4. A complete Linux system has a ton of files. Rsyncing them to another computer means reading them all which can slow down your Raspi considerably.

Have you considered a combination of

  1. An occasional shut down of your Raspi to make a bit-by-bit backup of the SD card on a separate computer (e.g. using dd) and
  2. using rsync to copy your most important files (e.g. /home, software built from source in /usr/local or /opt) to another computer periodically?
  3. Dumping a list of the installed packages into a file so you can easily install them later if you need to?

That way you can combine the peace of mind that comes with a simple bit-by-bit backup that is less likely to go wrong with the convenience of frequent automatic backups of your most important files.

1
  • The approach you have suggested makes sense. Especially point no. 3 about dumping a list of installed packages into a file and making that part of the backup routine. Thank you so much for your kind help!
    – Sun Bee
    May 8, 2020 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.