TechNote: Backing up a Debian node with rdiff-backup
TechNote-1, November 24, 2024: Installing and using rdiff-backup on a Debian 12 machine.
Contents
Platform: Debian 12 running AllStarLink 3
I deleted key files during an upgrade
Previous newsletter to the rescue
Copied the virtual machine
My Tool of choice is rdiff-backup
Installing rdiff-backup to Debian 12
Backing up a directory
Scripting the backup
Converting the “old style” script to new
Summary
Platform: Debian 12 running AllStarLink 3
It had been a while since I did the update/upgrade dance on node 588411, running AllStarLink 3 (ASL3). That dance is done in a Debian terminal window:
sudo apt update
sudo apt upgrade -y
I deleted key files during an upgrade
There were 96 packages to upgrade so away I went with upgrading. Unfortunately, I wasn’t really paying careful attention so when the process stalled with a prompt about keeping or upgrading a particular file, I just plugged in a capital Y in and hit Enter. A few moments later, I realized the prompt was asking me if I wanted to replace my existing configuration file with a new, stock file — and I had answered yes, meaning my configuration file was just overwritten.
Oh man. This was one of those unthinking moments that can cause you significant frustration.
I had answered yes to replacing my pjsip.conf file and simpleusb.conf files before I caught myself. Simpleusb.conf? Reproducing the correct configuration in this file was pretty easy. The pjsip.conf file, though, was another matter. This configuration file tells node 588411 how to communicate with my Cisco SPA525G phone. When I first got it working, it was more than a couple of hours of twiddling and fiddling to achieve success, so I was particularly worried about how much work it was going to take to restore that connection.
Previous newsletter to the rescue
Fortunately, I had documented the settings I used in pjsip.conf back in issue 98. Those notes helped me quickly get node 588411 talking to my SIP phone again.
Whew! Crisis averted.
But clearly, I needed to prevent this kind of problem in the future, and that means having a good backup of my AllStarLink files.
Copied the virtual machine
You might recall that 588411 runs inside a virtual machine. An easy way to back it up is to simply make a copy of the virtual machine. I’ve done that. It took about 10 minutes to export the virtual machine as a .ova file. The .ova file is stored off the host machine on my Synology backup device.
My Tool of choice is rdiff-backup
Since then, I’ve installed rdiff-backup to the virtual machine running node 588411. The Remote Differential Backup tool — abbreviated as rdiff-backup — has been around for about 20 years and went through a significant rewrite in 2020. It backs up one directory to another, either locally or remotely. It runs on Linux, Windows, and MacOS.
Installing rdiff-backup to Debian 12
Installation of rdiff-backup follows the usual “apt install” routine:
sudo apt install rdiff-backup
Backing up a directory
Syntax for backing up on the virtual machine is simple. In this example, I’m backing up the original /etc/allmon3 folder (the source) to a folder at /etc/backups/allmon3 (the target):
sudo rdiff-backup /etc/allmon3 /etc/backups/allmon3
Scripting the backup
To make backing up to easier and to reduce the likelihood of mistyping a command, I wrote a simple bash script. The script commands copy four folders to their equivalent folders in the /etc/backups space:
#!/bin/bash
sudo rdiff-backup /etc/allmon3 /etc/backups/allmon3
sudo rdiff-backup /etc/asterisk /etc/backups/asterisk
sudo rdiff-backup /usr/share/asterisk/agi-bin /etc/backups/agi-bin
sudo rdiff-backup /var/www/html /etc/backups/html
The first two lines cover backing up configuration files in Allmon3 and Asterisk. The third line backs up my announcement commands for the node. The fourth line picks up the AllScan instance in /var/www/html/allscan.
I named the bash script “backup-asterisk.sh” and changed it to be executable:
cd ~
sudo chmod +x backup-asterisk.sh
I put this script in the root directory. “cd ~” takes me to the root home directory.
To run the script:
cd ~
sudo sh backup-asterisk.sh
Alternatively, when I’m operating as root, I can simply change to the root home directory and execute the bash file, like this:
cd ~
./backup-asterisk.sh
Converting the “old style” script to new
Please note that my syntax for rdiff-backup is in the old style of rdiff-backup commands. It will spawn some error messages for each execution of rdiff-backup in the bash script:
WARNING: this command line interface is deprecated and will soon disappear, start using the new one as described with ‘—new —help’.
Accordingly, I’ve updated the bash script syntax to use the new terminology, which simply adds an explicity command to backup to my existing commands:
#!/bin/bash
sudo rdiff-backup backup /etc/allmon3 /etc/backups/allmon3
sudo rdiff-backup backup /etc/asterisk /etc/backups/asterisk
sudo rdiff-backup backup /usr/share/asterisk/agi-bin /etc/backups/agi-bin
sudo rdiff-backup backup /var/www/html /etc/backups/html
To suppress warnings, I’ve also decreased the level of verbosity. There are 10 verbosity levels:
0 No information given
1 Fatal Errors displayed
2 Warnings
3 Important notes, and maybe later some global statistics (default)
4 Some global settings, miscellaneous messages (obsolete)
5 Mentions which files were changed, and other info
6 More information on each file processed (obsolete)
7 More information on various things (obsolete)
8 Debug, without timestamp
9 Also debug, but with timestamp
When set to verbosity level 3 (the default level), a backup of the Allmon3 instance returns this message:
NOTE: Starting increment operation from source path /etc/allmon3 to destination path /etc/backups/allmon3
To suppress errors and warnings, I specified verbosity level 2 in the script modification below. Note that the order of operators is important. If you put “-v2” (for verbosity level 2) after the “backup” argument, the script will fail.
#!/bin/bash
sudo rdiff-backup -v2 backup /etc/allmon3 /etc/backups/allmon3
sudo rdiff-backup -v2 backup /etc/asterisk /etc/backups/asterisk
sudo rdiff-backup -v2 backup /usr/share/asterisk/agi-bin /etc/backups/agi-bin
sudo rdiff-backup -v2 backup /var/www/html /etc/backups/html
At verbosity level 5 and above, the amount of information returned increases substantially. Here is verbosity level 5 for an incremental backup of my Allmon3 instance:
* Using repository '/etc/backups/allmon3'
* Unable to import win32security module. Windows ACLs not supported by filesystem at path /etc/allmon3
* Could not determine if source directory /etc/allmon3 permits trailing spaces or periods in filenames because we can't find any files with trailing dot/period. It will be treated as permitting such files, but none will exist if it doesn't, so it doesn't really matter and is harmless
* -----------------------------------------------------------------
Detected abilities for source (read only) file system:
Access control lists On
Extended attributes On
Windows access control lists Off
Case sensitivity On
Escape DOS devices Off
Escape trailing spaces Off
Mac OS X style resource forks Off
Mac OS X Finder information Off
-----------------------------------------------------------------
* Unable to import win32security module. Windows ACLs not supported by filesystem at path /etc/backups/allmon3/rdiff-backup-data/rdiff-backup.tmp.0
* -----------------------------------------------------------------
Detected abilities for destination (read/write) file system:
Ownership changing On
Hard linking On
fsync() directories On
Directory inc permissions On
High-bit permissions On
Symlink permissions Off
Extended filenames On
Windows reserved filenames Off
Access control lists On
Extended attributes On
Windows access control lists Off
Case sensitivity On
Escape DOS devices Off
Escape trailing spaces Off
Mac OS X style resource forks Off
Mac OS X Finder information Off
-----------------------------------------------------------------
* Backup: escape_dos_devices = False
* Backup: escape_trailing_spaces = False
* Given repository doesn't need to be regressed
NOTE: Starting increment operation from source path /etc/allmon3 to destination path /etc/backups/allmon3
* Cleaning up
Higher verbosity levels result in much more output. I’m not going to put examples here because it’s doubtful you’ll ever need them and they take up a lot of space.
Summary
To use rdiff-backup, install rdiff-backup in Debian 12 from a terminal window:
sudo apt install rdiff-backup
Run rdiff-backup to copy a source folder to a local target folder using this syntax:
sudo rdiff-backup [source folder] [target folder]
That is old-style syntax that will spawn a message. If you don’t want to see non-critical messages, decrease the verbosity level to 1 or 2. The following syntax also uses the new syntax style:
sudo rdiff-backup -v2 backup [source folder] [target folder]
Script the command string to make it easier to run:
#!/bin/bash
sudo rdiff-backup -v2 backup [source folder] [target folder]
Save that code in a file ending in .sh then make it executable:
sudo chmod +x [your_script_file_name].sh
To run the script:
cd ~
sudo sh [your_script_file_name].sh
Or use this shorter version:
cd ~
./[your_script_file_name].sh