2023 Version with rdiff-backup. Install with:
sudo apt install rdiff-backup
We will NOT backup the entire OS. Doing so wastes storage that is easily put back using a normal installation, which is the 1st step in a restore.
We will show how to perform simple backups, capturing not just the data but basic system information to make recovery from non-disk failures easier.
You are meant to follow along, typing as we go.
Code:
#!/bin/bash
TGT=/Backups
DAYS=120
# Run backups and commands as root to maintain permissions, owners, groups, ACLs
# Ensure directories exist
mkdir -p /root/backups
# check that backup target storage is mounted; many different methods exist
# * check the mount for the expected directory
# * look for a "not-mounted" file that exists under the mount point
# Save list of manually installed packages - to be restored later
# Be certain the redirected file is part of your include backup locations
/usr/bin/apt-mark showmanual > /root/backups/apt-mark.manual
# Local Backups; all backups need to run as root, to capture file metadata
/usr/bin/rdiff-backup \
--exclude-sockets --exclude-device-files --exclude-fifos \
--exclude '**/.cache' --exclude "$TGT" \
--include /usr/local --include /etc \
--include /root --include /home \
--exclude '**' / "$TGT"
# Trim old backups from long ago
/usr/bin/rdiff-backup --remove-older-than "$DAYS" --force "$TGT"
The backup tool isn't really THAT important, provided it meets most of the best practices for a backup tool. rdiff-backup is the tool I use.
If your backups meet those requirements, even most of them, then you are doing well. It is possible to find an all-in-one tool that meets most, but not all, of those important characteristics.
I prefer restores that don't require a special tool to accomplish. This explains my choice in backup tool. 90% of the time, you'll need to restore the most recent file(s) in the backup, so having easy access to those is a key goal for my backups.
Restore order matters.
To restore 1 file, find it in the backup target storage and copy it back to the primary storage. Simple.
Or (do it the hard way): Code:
$ sudo rdiff-backup --restore-as-of (timespec) \
{path-to-backup-file} {path-to-restore-location}
The timespec is very flexible. The rdiff-backup manpage has them all in TIME FORMATS section. A few examples:
To restore a directory structure, I'd use
Code:
$ sudo rsync -avz {SRC} {DEST}
to restore it. Simple.
Or (do it the hard way), as shown for 1 file. Just have the {SRC} be the top-level directory to be restored.
Last Update: 2023-02-09