Incremental backup for directory using rdiff-backup
Published on: 14th Oct 2022
Overview
This utility provides the following features:
- Backup the directory or selected file to local or remote storage.
- Incremental backup will be created. This means, only the differences in the old and new files (i.e., "delta") will be send to the destination.
- It works with SSH (i.e., a secure shell communcation).
- This solution works on Windows, Linux, Unix and MacOS.
- Able to restore a selected file or directory.
- Able to remove the old backups.
Requirements
-
Both server and client must install
rdiff-backup
.For Ubuntu, run the following command to install this utility before backing up the data from your computer.
sudo apt install rdiff-backup
For Windows, download the EXE from the following site,
Operations on Windows platform with Powershell
-
First, I copied
rdiff-backup.exe
tod:\temp3
directory. This is to simplify the testing to this utility. Once you have confirmed that it met your expectation, you may copy the exe toc:\windows\system32
directory to make this command accessible from anywhere in your computer. -
Backup a directory,
.\rdiff-backup -v5 backup .\src .\bak
Backup 'src' directory to another server at 'bak' directory (
/home/user1/bak
),.\rdiff-backup -v5 backup .\src user1@your-domain.com::bak
Notes: it's advisable to setup the SSH key-based authentication to simplify the server access.
-
To restore a directory to a different location,
.\rdiff-backup -v5 restore .\bak .\src-restored
-
To view the incremental changes,
.\rdiff-backup list increment .\bak
-
To remove an older increments,
.\rdiff-backup remove increments --older-than 2W user1@your-domain.com::/remote-dir .\rdiff-backup remove increments --older-than 7D .\bak .\rdiff-backup remove increments --older-than 4B .\bak
Where:
2W
is 2 weeks.7D
is 7 days.4B
is 4 backup.
Setup for SSH with key authentication
-
To backup files (in Windows) to a remote backup server, please follow the steps below:
-
Install openSSH client.
For Windows 10 or Windows 2019,
Add-WindowsCapability -Online -Name OpenSSH.Client*
For Winwdows 2012R2 or 2016, download the files from the following site,
https://github.com/PowerShell/Win32-OpenSSH
Alternatively, install
PuTTY
from the following site, -
Then, run PowerShell console.
-
Goto user's home directory.
-
Create
.ssh
directory,cd ~ mkdir .ssh cd .ssh
-
Generate key pairs for SSH using OpenSSH for Powershell,
ssh-keygen
Alternatively, you may use
puttygen.exe
program to generate the key pairs (id_rsa
andid_rsa.pub
) and saves the files into.ssh
directory.Notes:
- Please leave blank for the passphrase so that you can ease the backup process. By defualt, it generates a file
id_rsa
andid_rsa.pub
- Please leave blank for the passphrase so that you can ease the backup process. By defualt, it generates a file
-
Copy
id_rsa.pub
to the backup server,scp id_rsa.pub user1@your-domain.com:authorized_keys
This will copy the file from the local server to the backup server (your-domain.com) and place the file into 'user1' home directory.
-
Logon to the backup server (Ubuntu server in this example).
-
Move the 'authorized_keys' file to '.ssh' directory.
cd /home/user1 sudo mkdir .ssh sudo mv authorized_keys .ssh/authorized_keys
-
-
Once the public key (
id_rsa.pub
) has been uploaded to the backup server, you will be able to back up the files to a remote server without entering your password.For Powershell,
cd d:\temp3 .\rdiff-backup -v5 backup .\src user1@your-domain.com::bak
In DOS prompt,
rdiff-backup -v5 backup d:\temp3\src user1@your-domain.com::bak
References
-
Project site
-
Source code
Jump to #UBUNTU blog
Author
Lau Hon Wan, software developer.