A Comprehensive Guide to Using the Duplicity Command (with examples)
Duplicity is a powerful command-line tool for creating incremental, compressed, encrypted, and versioned backups. In addition, it supports uploading backups to various backend services. With its versatile features, Duplicity provides a reliable solution for data backup and restoration. This article will explore different use cases of the Duplicity command and provide practical examples to help you understand its capabilities.
Use Case 1: Backup a directory via FTPS to a remote machine, encrypting it with a password
FTP_PASSWORD=ftp_login_password PASSPHRASE=encryption_password duplicity path/to/source/directory ftps://user@hostname/target/directory/path/
Motivation: If you need to back up a directory to a remote machine via FTPS, this use case is suitable for you. By encrypting the backup with a password, it ensures the security of your data during transit.
Explanation:
FTP_PASSWORD=ftp_login_password
: Sets the password for FTP login authentication.PASSPHRASE=encryption_password
: Sets the passphrase for encrypting the backup.duplicity
: The command itself.path/to/source/directory
: Specifies the source directory that you want to back up.ftps://user@hostname/target/directory/path/
: Specifies the FTPS URL of the remote machine and the target backup directory.
Example Output:
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: Mon Feb 15 2022 10:34:12 PM EST
Use Case 2: Backup a directory to Amazon S3, doing a full backup every month
duplicity --full-if-older-than 1M --use-new-style s3://bucket_name[/prefix]
Motivation: Regular full backups are essential to ensure data integrity and minimize the risk of data loss. By specifying the --full-if-older-than
argument, you can instruct Duplicity to perform a full backup if the last one was taken more than a month ago.
Explanation:
--full-if-older-than 1M
: Triggers a full backup if the last backup is older than 1 month.--use-new-style
: Uses a more straightforward naming scheme for backup files.s3://bucket_name[/prefix]
: Specifies the Amazon S3 bucket and optional prefix for storing the backup.
Example Output:
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: Sat Jan 01 2022 12:00:00 AM EST
Use Case 3: Delete versions older than 1 year from a backup stored on a WebDAV share
FTP_PASSWORD=webdav_login_password duplicity remove-older-than 1Y --force webdav[s]://user@hostname[:port]/some_dir
Motivation: Over time, backups can consume a significant amount of storage space. With this use case, you can delete old backup versions that are no longer necessary, freeing up storage resources.
Explanation:
FTP_PASSWORD=webdav_login_password
: Sets the password for WebDAV login authentication.duplicity
: The command itself.remove-older-than 1Y
: Specifies that versions older than 1 year should be deleted.--force
: Forces the removal operation without user confirmation.webdav[s]://user@hostname[:port]/some_dir
: Specifies the WebDAV URL of the backup location.
Example Output:
Found 5 backup sets. Trying to guess which ones are to be deleted (if any) ...
No backup sets found or no sets older than 1Y to delete.
Use Case 4: List the available backups
duplicity collection-status "file://absolute/path/to/backup/directory"
Motivation: Before performing any backup-related actions, it is often helpful to know the status of your existing backups. This use case allows you to list the available backup sets along with their metadata.
Explanation:
collection-status
: Retrieves the status and metadata of the available backup sets."file://absolute/path/to/backup/directory"
: Specifies the absolute path to the backup directory.
Example Output:
Found 3 secondary backup chains.
Chain start time: Sun Jan 02 2022 12:00:00 AM EST
Chain end time: Wed Jan 05 2022 12:00:00 AM EST
Use Case 5: List the files in a backup stored on a remote machine, via ssh
duplicity list-current-files --time YYYY-MM-DD scp://user@hostname/path/to/backup/dir
Motivation: When you want to explore the contents of a specific backup, knowing the list of files included can be beneficial. This use case allows you to list all the files in a backup stored on a remote machine via SSH.
Explanation:
list-current-files
: Lists the files contained in the specified backup.--time YYYY-MM-DD
: Specifies the date for which you want to retrieve the file list.scp://user@hostname/path/to/backup/dir
: Specifies the SSH URL of the remote machine and the path to the backup directory.
Example Output:
file1.txt
file2.png
dir/
dir/file3.jpg
Use Case 6: Restore a subdirectory from a GnuPG-encrypted local backup to a given location
PASSPHRASE=gpg_key_password duplicity restore --encrypt-key gpg_key_id --file-to-restore relative/path/restoredirectory file://absolute/path/to/backup/directory path/to/directory/to/restore/to
Motivation: If you only need to restore a specific subdirectory from a GnuPG-encrypted backup, this use case is suitable for you. It allows you to restore the desired directory to a specified location.
Explanation:
PASSPHRASE=gpg_key_password
: Sets the passphrase for decrypting the GnuPG-encrypted backup.duplicity
: The command itself.restore
: Initiates the restoration process.--encrypt-key gpg_key_id
: Specifies the GnuPG key ID used for encryption.--file-to-restore relative/path/restoredirectory
: Specifies the relative path of the directory to restore.file://absolute/path/to/backup/directory
: Specifies the absolute path to the backup directory.path/to/directory/to/restore/to
: Specifies the location to restore the directory.
Example Output:
Restoring file1.txt to path/to/directory/to/restore/to
Restoring file2.png to path/to/directory/to/restore/to
Restoring dir/file3.jpg to path/to/directory/to/restore/to/dir/
By following the different use cases showcased in this comprehensive guide, users can leverage the powerful features of the Duplicity command for their backup and restoration needs. The provided examples demonstrate the versatility of Duplicity and how it can be applied to various scenarios. Remember to adapt the command arguments and parameters according to your specific requirements.