In this article, I will provide an example of how to install and use Duplicity. Creation of full and incremental backups to local and remote servers.
Install command in Ubuntu:
apt update
apt install duplicity
duplicity -V
We will also install the necessary components (for example, python-paramiko is required for scp connections, ncftp for ftp connections):
apt install python-paramiko ncftp
Here’s an example of backing up to a file on a local server and restoring to another directory:
duplicity --no-encryption /home/test file:/home/backup_test
duplicity restore --no-encryption file:/home/backup_test /home/restore
You can check the integrity of the backup after creating it:
duplicity verify --no-encryption file:/home/backup_test /home/test
On first startup, duplicity performs a full backup, and on subsequent runs, an incremental backup to force a full backup:
duplicity full --no-encryption /home/test file:/home/backup_test
Backup to another server via SCP (SSH):
duplicity --no-encryption /home/test scp://test@ixnfo.com//home/test/backups
You can exclude directories from backup:
duplicity full --no-encryption --exclude /home/test/dir1 -exclude /home/test/dir2 /home/test scp://test@ixnfo.com//home/test/backups
Restoring a directory from a backup copy, by default the existing directory is not overwritten, so you can restore it to a separate directory:
duplicity restore --no-encryption scp://test@ixnfo.com//home/test/backups /home/test_restore
Or into an existing one but specifying –force:
duplicity restore --force --no-encryption scp://test@ixnfo.com//home/test/backups /home/test
You can check by counting the number of files:
find /home/test_restore/ -type f | wc -l
find /home/test/ -type f | wc -l
Use the –force option with caution, as if the path is specified incorrectly, important directories may be erased.
An example of restoring only one file from a backup copy (specifying the file name in the path for saving is required! If you simply indicate that you need to restore the file to the /home/test directory, then this directory will be deleted and there will be a file named test instead):
duplicity restore --no-encryption --file-to-restore ixnfo.sh scp://test@ixnfo.com//home/test/backups /home/test/ixnfo.sh
Restore a file 5 days ago (and check the differences if it’s a text file):
mkdir /duplicity/
duplicity restore -t 5D --no-encryption --file-to-restore ixnfo.sh scp://test@ixnfo.com//home/test/backups /duplicity/ixnfo.sh
diff /home/test/backups/ixnfo.sh /duplicity/ixnfo.sh
You can also specify s for seconds, m for minutes, h for hours, D for days, W for weeks, M for months, Y for years.
Backing up to a directory on an FTP server:
FTP_PASSWORD=password duplicity /home/test ftp://test@ixnfo.com/backup
An example of creating a backup copy of the /etc/ directory to a remote server via sftp:
duplicity /etc/ sftp://test@ixnfo.com//backups
If you need to encrypt/decrypt data, then we generate GPG keys:
gpg --gen-key
Let’s see the public key and use it:
gpg --list-keys
duplicity --encrypt-key="01A323FB259A9C482C41B1532A5F7D757D16180F" /home/test scp://test@ixnfo.com//home/test/backups
An example of viewing information about backups:
duplicity collection-status file:/home/backup_test
View the list of files in the backup:
duplicity list-current-files file:/home/backup_test
To force deletion of backups older than 30 days:
duplicity remove-older-than 30D --force file:/home/backup_test
See also my articles:
Installing and Configuring fsbackup
Installing and using rsync on Linux
My other articles on the topic of Backup