Duplicity wraps librsync, tar, and GPG into one tool that produces encrypted, signed, forward-incremental backups on top of object storage. It is one of the oldest “encrypted backup to a dumb bucket” tools and still in active service on a lot of Linux fleets, especially where chunked tools like restic or BorgBackup were ruled out for stack-uniformity reasons. This article covers a working S3 deployment, the GPG key management that the project glosses over, and the operational caveats we apply when Duplicity is on the menu.
How to verify
A working Duplicity install on Ubuntu and a smoke run against an S3 bucket:
apt list --installed 2>/dev/null | grep -E 'duplicity|python3-boto3'
duplicity --version
gpg --list-keys
duplicity collection-status "s3://s3.us-east-1.amazonaws.com/<bucket>/<host>/"
duplicity verify --compare-data "s3://s3.us-east-1.amazonaws.com/<bucket>/<host>/" /srv
collection-status reads the manifest files in the bucket and prints the chain of full + incrementals. verify --compare-data re-downloads and decrypts the volumes to confirm the bucket contents match the local source — the closest thing to a non-destructive restore drill.
What’s happening
Duplicity does a tar of changed bytes (per librsync signatures of the previous backup) and uploads the resulting tar volumes encrypted with GPG to the destination. Each backup chain has one full (everything) followed by incrementals (deltas against the previous). Restore replays the chain forward: full → inc 1 → inc 2 → … → target snapshot.
The forward-incremental design has a sharp edge: a corrupted full or any intermediate incremental kills the entire chain from that point forward. That’s why operators schedule periodic new fulls — Duplicity will not start a new chain on its own. The typical pattern is duplicity full weekly or monthly, duplicity incremental daily.
On S3, every backup writes three file types: duplicity-full.<ts>.vol*.difftar.gpg (the data), duplicity-full.<ts>.manifest.gpg (what’s in each volume), and duplicity-full.<ts>.sigtar.gpg (the librsync signatures the next incremental compares against). Compression and encryption mean the bucket sees binary blobs — no point trying to browse with the S3 console.
The procedure
-
Install Duplicity and the S3 backend.
apt install -y duplicity python3-boto3 gnupg -
Generate a backup GPG keypair. Use a dedicated key — do not reuse the operator’s personal GPG identity. Store the private key in a vault (Bitwarden, HashiCorp Vault, AWS Secrets Manager) plus a hard-copy paper backup.
gpg --batch --gen-key <<EOF %no-protection Key-Type: RSA Key-Length: 4096 Name-Real: backup-acme-prod Name-Email: backup@acme.example Expire-Date: 0 %commit EOF gpg --export-secret-keys --armor backup@acme.example > /root/.backup-key.asc -
Create an S3 bucket and an IAM principal scoped to it. The IAM policy needs
s3:ListBucket,s3:GetObject,s3:PutObject,s3:DeleteObjecton the bucket and its objects — and nothing else. -
Wire credentials into the environment used by the backup cron. Do not put them in shell history.
install -m 0600 /dev/null /etc/duplicity/env cat > /etc/duplicity/env <<'EOF' AWS_ACCESS_KEY_ID=<key> AWS_SECRET_ACCESS_KEY=<secret> PASSPHRASE=<gpg-key-passphrase-or-empty-if-no-protection> EOF -
Take the first full backup.
set -a; . /etc/duplicity/env; set +a duplicity full \ --encrypt-key backup@acme.example \ --sign-key backup@acme.example \ --volsize 250 \ /srv \ "s3://s3.us-east-1.amazonaws.com/acme-backups/$(hostname -s)/srv/"--volsize 250produces 250 MiB tar volumes; the default 25 MiB is small for S3 transfer. -
Schedule the rotation. The pattern we use is daily incrementals, weekly fulls, monthly purge of fulls older than the retention window.
# /etc/cron.d/duplicity 10 02 * * 1-6 root . /etc/duplicity/env && duplicity incremental --encrypt-key backup@acme.example --sign-key backup@acme.example --volsize 250 /srv "s3://..." 10 02 * * 0 root . /etc/duplicity/env && duplicity full --encrypt-key backup@acme.example --sign-key backup@acme.example --volsize 250 /srv "s3://..." 30 03 * * 0 root . /etc/duplicity/env && duplicity remove-all-but-n-full 4 --force "s3://..." -
Test a restore monthly. The only test that counts is restoring real files to a scratch host.
. /etc/duplicity/env duplicity restore --file-to-restore etc/hostname \ "s3://s3.us-east-1.amazonaws.com/acme-backups/<host>/srv/" /tmp/restore-hostname
Operational notes
- The GPG passphrase ends up in environment files; treat them like database creds. We mount them via systemd
LoadCredential=or a Vault-Agent template rather than dropping clear-text in/etc/. duplicity cleanup --forceis required when a previous run was interrupted — leftover partial volumes block the next backup with cryptic errors.- Chain length: each incremental compounds the restore time. We cap chains at 7-30 incrementals (one full per week or per month) depending on data volume. Long chains also mean a single corrupted manifest invalidates everything after it.
- Object-lock / WORM buckets are awkward — Duplicity expects to be able to delete during cleanup. Use a lifecycle rule, not bucket-level retention.
- For multi-TB filesystems, Duplicity is the wrong choice. The librsync signature step rescans the whole tree; restic or BorgBackup handle that scale much better. Duplicity shines in the 1-200 GB range.
In the engagements we run, Duplicity sits in legacy fleets where the GPG-encrypted, dumb-bucket pattern was decided years ago and where the operations team has built tooling around it. We modernize the wrapper — secrets via systemd credentials, restores wired into CI, retention as code in Terraform — and treat the bucket as one tier of a multi-tier strategy that always has a second, structurally different copy elsewhere. The broader picture sits in Managed Operations.