|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Backing up a Raspberry Pi Live" |
| 4 | +date: 2023-06-16 08:00:00 -0400 |
| 5 | +category: "Service Setup" |
| 6 | +tags: ['raspberry pi', 'backup'] |
| 7 | +--- |
| 8 | + |
| 9 | +In a effort to keep all my devices backed up, I have been looking into a way to backup my Raspberry Pi devices. |
| 10 | + |
| 11 | +## Approach |
| 12 | + |
| 13 | +My criteria for success, in order, has been: |
| 14 | + |
| 15 | +1. Accurate |
| 16 | +1. Testable |
| 17 | +1. Easy to revert |
| 18 | +1. Automatic |
| 19 | +1. Fast |
| 20 | + |
| 21 | +Obviously the most important thing about any backup is that it is accureate and can be successfully restored. My first thought was just pulling the flash drive they boot off of and using clonezilla to make an image. This would require me to have the disipline and memory to shutdown the device regularly and pull the flash drive for backup. I would prefer something a bit more automatic but I know options like `dd` are not viable running against an active device. |
| 22 | + |
| 23 | +That's when I came accross `image-utilities`. It spawned from a rasperry pi forum post in 2019, but has been slightly maintained since then [in GitHub](https://github.com/seamusdemora/RonR-RPi-image-utils). It uses a bash script and rsync to make a copy of the running device, and is even able to make incremental backups. |
| 24 | + |
| 25 | +To install it, follow the guide on the github page, but here is a simplified version. |
| 26 | + |
| 27 | +## Scripts Install |
| 28 | + |
| 29 | +> Don't just take my word for it. Always inspect the code that will be running on your machines, especially from an untrusted and unsigned source. |
| 30 | +
|
| 31 | +```bash |
| 32 | +git clone https://github.com/seamusdemora/RonR-RPi-image-utils.git ./image-utils |
| 33 | +cd ./image-utils |
| 34 | +ls -lah |
| 35 | +``` |
| 36 | + |
| 37 | +Once you have the files, you'll need to move them to the user binary directory. |
| 38 | + |
| 39 | +```bash |
| 40 | +sudo cp image-* /usr/local/sbin/ |
| 41 | +sudo chmod 755 /usr/local/sbin/image-* |
| 42 | +``` |
| 43 | + |
| 44 | +## Running the Backup |
| 45 | + |
| 46 | +Now you should be able to use `image-backup`. I typically run the following command, and even add it to crontab. |
| 47 | + |
| 48 | +```bash |
| 49 | +sudo image-backup --initial /mnt/backup/$(date +"%Y-%m-%d").img,,5000 |
| 50 | +``` |
| 51 | + |
| 52 | +The backup run time will depend on your device and how much data it needs to copy. It is surprisingly fast though. 15GB ususually runs for 2+ minutes on a Raspberry Pi 4B. |
| 53 | + |
| 54 | +> Backup can be pretty large, ~15GB depending on how much you have running on your Pi |
0 commit comments