Back-ups in Linux
Published -I've been using computers since the time when you powered up and it just ran. The OS(Operating System) was baked into the hardware, so you didn't have to worry about making back-ups.
When I got my Amiga I made a copy of my workbench disks and kept the original in the top draw of my desk. I didn't need any other back-ups.
Then there was the PC era, and I messed up my DOS/Windoze installs so regularly that I just got good at reinstalling the OS. So much so that I got my Windoze 95 install time down to 15 minutes with a 3.5" boot-disk and a copy of the ISO on a ZIP disk and that included installing all the drivers. And the expectation of catastrophic OS disaster has followed me, something goes wrong with the OS for whatever reason, just "Nuke and Pave".
This means that I have always tested my recovery solutions as I've gone along. A few time I've lost stuff, but for the most part, I've been ok.
Shortly after I started using Linux as my full time/only OS. I found a good set-up was to have the /home folder on a second drive. During the reinstall, select other when you asked what you want to do with the current OS, so you can set up the drives and partitions with the OS on the Primary and /home as the whole of the Secondary. Create the same user each time and you're done. Then you just need some way of backing up your home drive.
Enter bu by Joe Collins described as:-
A simple tool to create reliable backups of /etc/ and /home from multiple Debian/Ubuntu Linux systems.
I've used it on the regular since v1(before that i was using his XBT script). I "fixed" an issue I had where rsync would just crash with no error code and I'd need to restart, but then it'd finish fine.
I always thought there was more I could be backing up for a good recovery. So I rewrote it a little and I present to you my interpretation of bu.
BU - USB Backup Tool
Version 2.0 - A robust backup solution for Debian/Ubuntu systems, designed to protect your data and system configuration against disk failure.
⚠️ Disclaimer
USE THIS SCRIPT AT YOUR OWN RISK.
- The script is provided “AS IS”, without warranty of any kind, either expressed or implied.
- The author assumes no responsibility for data loss, system corruption, hardware damage, or any other issues that may arise from using this tool.
- You are solely responsible for ensuring that your backups are complete and restorable.
- It is strongly recommended to test the backup and restore process on a non‑critical system before relying on it for disaster recovery.
- Always verify that your USB drive is correctly labelled and has sufficient space before starting.
Description
BU (USB Backup) creates a mirror backup of your Debian/Ubuntu system onto a dedicated USB drive labelled BU_Drive.
The backup includes:
/etc- system-wide configuration/home- all user data and settings- System blueprint - package lists, crontabs,
/root,/usr/local,/opt, and custom GPG keyrings
This blueprint allows you to rebuild a fully functional system in ~1 hour after a catastrophic disk failure, saving you days of manual reconfiguration.
Features
- Delta-based space check - only checks for the net increase in data, not the total source size
- Automatic dependency installation - installs
rsyncandlessif missing (viaapt) - Coloured output for clear progress and error reporting
- Shutdown mode - backup then cleanly shut down the system
- Restore mode - safely restore
/homefrom the backup - Exclusions - automatically excludes caches, thumbnails, and trash
- Detailed logging - backup log saved on the USB drive
- Trap signals - clean exit on Ctrl+C
Requirements
- A USB drive (or external disk) with a Linux-native filesystem (e.g.,
ext4,XFS) - The partition must be labelled
BU_Drive(case-sensitive) rsyncandless(the script will try to install them automatically viaapt)sudoprivileges for backup and restore operations- Debian or Ubuntu (or any derivative with
aptanddpkg)
Installation
Download the script
wget https://codeberg.org/mort8088/bu/raw/branch/main/bu.shMake it executable
chmod +x bu.sh(Optional) Install system-wide
sudo cp bu.sh /usr/local/bin/bu
Now you can run it simply as bu from anywhere.
USB Drive Setup
Before using BU, prepare your USB drive:
Partition and format with a Linux filesystem (e.g.,
ext4).
Usinggpartedor command line:sudo mkfs.ext4 /dev/sdX1 # replace with your deviceLabel the partition as
BU_Drive:sudo e2label /dev/sdX1 BU_DrivePlug it in - the system should auto-mount it. If not, mount it manually:
sudo mount /dev/sdX1 /media/bu
Now your drive is ready.
Usage
Run the script from the terminal. Don't run it with sudo from the command line, all commands use sudo internally - you will be prompted when needed.
./bu.sh [OPTION]
| Option | Description |
|---|---|
| (no option) | Perform a full backup (interactive). |
--shutdown or -s | Backup then shut down the system if successful. |
--restore | Restore /home from the backup (destructive - see warning below). |
--help or -h | Show detailed help. |
Examples
Normal backup
./bu.shBackup and shutdown
./bu.sh --shutdownRestore
/home./bu.sh --restore
How It Works
- Checks for dependencies - installs
rsyncandlessif missing. - Finds the USB drive - looks for a mounted partition labelled
BU_Drive. - Calculates required space - uses a delta approach (explained below).
- Saves the system blueprint - package selections, crontabs, and critical system directories.
- Performs the mirror backup with
rsync- copies/etcand/homewhile excluding caches and trash. - Logs the operation - the backup log is stored on the USB drive. This can get rather large delete it when done.
Restore Procedure (Disaster Recovery)
If your main hard drive fails, follow these steps to restore your system:
- Install a base Debian/Ubuntu on a new hard drive.
- Plug in your BU_Drive and ensure it is mounted.
- Install BU on the new system (or just run the script from the USB).
- Restore
/etcand/homemanually (or use the script's--restorefor/home):- Copy
/etcfrom the backup:sudo rsync -a /media/bu/BU_Backups/$(hostname)/etc/ /etc/ - Restore
/homeusing the script:./bu.sh --restore
- Copy
- Reinstall all packages from the saved list:
sudo cp -a /media/bu/BU_Backups/$(hostname)/keyrings-backup/* /usr/share/keyrings/ sudo dpkg --set-selections < /media/bu/BU_Backups/$(hostname)/sysinfo/dpkg-selections.txt sudo apt-get dselect-upgrade - Copy back custom system folders (
/root,/usr/local,/opt) from the backup.
After a reboot, your system will be fully restored.
Space Check - Delta Mode
BU uses a delta space check to avoid false alarms. Instead of requiring free space equal to the entire source, it only verifies that you have enough space for the net increase in data plus a 1 GiB safety buffer.
- If the backup is larger than the source (because files were deleted locally), no extra space is required.
- This is especially useful when your drive is nearly full but you're only adding a few small files.
Troubleshooting
| Issue | Solution |
|---|---|
| "No drive with label 'BU_Drive' found" | Ensure the USB is plugged in, mounted, and correctly labelled. Check with lsblk -o LABEL,MOUNTPOINT. |
| "Insufficient free space" | The delta check indicates not enough room for the new/changed data. Free up space on the drive or use a larger one. |
| Rsync errors during backup | Check the log file on the drive (BU_Backups/$(hostname)/backup.log) for details. Try rerunning the backup. |
| Restore fails | Make sure the drive is mounted and the backup directory exists. If needed, remount and retry. |
| Script asks for password repeatedly | sudo caches credentials for a short time; if you step away, you may need to re-enter. |
Credits
- Based on the USB Backup Tool (Version 1.1) by Joe Collins.
- Enhanced with delta space checks, blueprint saving, and improved error handling.
License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
See the LICENSE file for full details.
Happy backing up! 🛡️
