duplicity backs up directories encrypted and incrementally to remote storage. After an initial full backup only changes are transferred, and the storage provider only ever sees data encrypted with GnuPG. Possible targets include SFTP servers, WebDAV (e.g. Nextcloud), S3-compatible storage or online storage such as Strato HiDrive.
Installation
# Ubuntu / Debian
sudo apt install duplicity
# Fedora
sudo dnf install duplicity
Target addresses
| Target | Example URL |
|---|---|
| SFTP (path relative to home) | sftp://user@server/backup |
| SFTP (absolute path) | sftp://user@server//srv/backup |
| WebDAV over HTTPS | webdavs://user@cloud.example.org/remote.php/dav/files/user/backup |
| S3-compatible | s3://bucket-name/path |
| Local / USB disk | file:///mnt/usb/backup |
For SFTP, an SSH key without a passphrase should be set up for root so that the backup can run unattended. Insecure FTP should no longer be used.
Backup script
File /opt/backup/duplicity.sh:
#!/usr/bin/env bash
set -euo pipefail
export PASSPHRASE='put-a-long-random-passphrase-here'
TARGET="sftp://backup@backupserver//srv/backup/$(hostname)"
# Backup: full once a month, incremental otherwise
duplicity --full-if-older-than 1M \
--exclude /var/cache --exclude /var/tmp \
--include /etc --include /var/www --include /home \
--exclude '**' \
/ "$TARGET"
# Delete backup chains older than 6 months
duplicity remove-older-than 6M --force "$TARGET"
unset PASSPHRASE
sudo chmod 700 /opt/backup/duplicity.sh
The order of the --include/--exclude rules matters: the first matching rule wins. The final --exclude '**' excludes everything that was not explicitly included before.
Be sure to keep the passphrase in a safe place as well, for example in a password manager such as KeePassXC. Without it the backup is worthless.
Running it automatically
# sudo crontab -e
15 3 * * * /opt/backup/duplicity.sh >> /var/log/duplicity.log 2>&1
Checking the status and restoring
export PASSPHRASE='…'
TARGET="sftp://backup@backupserver//srv/backup/$(hostname)"
# Overview of full and incremental backups
duplicity collection-status "$TARGET"
# List the backed-up files
duplicity list-current-files "$TARGET"
# Restore everything into a test directory
duplicity restore "$TARGET" /tmp/restore
# Restore the state from 3 days ago
duplicity restore --time 3D "$TARGET" /tmp/restore-3d
You should test a restore every now and then – a backup that cannot be restored is not a backup.
Alternatives
If you would like a graphical interface: Déjà Dup (preinstalled on Ubuntu as “Backups”) uses duplicity behind the scenes. For larger amounts of data, restic and BorgBackup with deduplication are often faster and more space-efficient. For simple local archives a tar backup script is enough.
Originally published in 2011 for FTP backups on Ubuntu 10.04, completely revised in November 2026.