As the old joke goes, system administrators are divided into two groups: those who do not make backups, and those who already do backups. There are a great many backup systems, from the simplest self-written script to huge monsters at the cost of a Boeing. All systems are needed for different purposes and perform different tasks.
The main, most famous and popular system in the world of unix and linux is, of course, bacula. Bacula can do a lot — complex storage schedules and policies, data encryption and client-server traffic, on-the-fly operations management, dozens of ways to package and verify data. The complete list of bacula’s features takes up several pages of small text. The main minus of bakula is exactly where its plus is. Implementing and setting up a bacula is an adventure for at least a week. There is a lot of documentation (but it is still not enough). Bakula consists of 4 independent components (director, storage, filedaemon, console), each of which is configured and lives separately. All these components have complex relationships and must be directly accessible to each other, which also does not make life easier. An elementary bacula config can easily weigh tens of kilobytes (and bacula is very sensitive to typos in the config — at best it won’t be read at all, and at worst the service will crash). If you need to make backups from one or two servers — bacula is a clear overkill. Instead of a complex harvester, you need a simple and understandable hammer. And there is such a hammer — it’s called duplicity.
Duplicity is very simple. This is the only command that runs on the server where the data will be copied from. All she can:
This is where the functionality of duplicity ends. Nothing complicated, puzzling, non-obvious. A system that is clear as a brick.
- Time Formats
- Installation and setup
- URL Format
- Environment Variables
- Known Issues / Bugs
- A Note on Symmetric Encryption and Signing
- See Also
- Options
- Examples
- Резервное копирование
- File Selection
- Actions
- Name
- A Note on European S3 Buckets
- A Note on Imap
- Проверка и восстановление
- Operation and Data Formats
- Description
- A Note on Ubuntu One
Time Formats
duplicity uses time strings in two places. Firstly, many of the files duplicity creates will
have the time in their filenames in the w3 datetime format as described in a w3 note at http://www.w3.org/TR/NOTE-datetime. Basically they look like
«2001-07-15T04:09:38-07:00», which means what it looks like. The «-07:00» section means the time zone is 7 hours behind UTC.
Secondly, the -t, —time, and —restore-time options take a time string, which can be given in any of several formats:
the string «now» (refers to the current time)
a sequences of digits, like «123456890» (indicating the time in seconds after the epoch)
A string like «2002-01-25T07:00:00+02:00» in datetime format
A date format of the form YYYY/MM/DD, YYYY-MM-DD, MM/DD/YYYY, or MM-DD-YYYY, which indicates midnight on the day in question, relative to the current time
zone settings. For instance, «2002/3/5», «03-05-2002», and «2002-3-05» all mean March 5th, 2002.
Installation and setup
Duplity is included in the package of the same name, and is installed traditionally for your operating system:
#debian, ubuntu
apt-get install duplicity
#centos, redhat, fedora
yum install duplicity
Now you need to decide where the packets will be sent. Duplity cannot work with a remote server on its own — depending on the type of remote server, it will need one or another package. duplicity itself only “directs the process”. Most popular server types and packages:
If you plan to encrypt and/or sign a backup, you need to generate a gpg key. Encrypting a backup is recommended if there is no trust in the storage server. The rule of good manners says that there is never trust in anyone. Keep in mind that a backup is essentially a delayed security breach. The key is generated in a quite traditional way:
Key parameters (size, algorithm) do not need to be changed, they are quite reasonable. After the generation is completed, GPG will return the key identifier. You can also watch it like this:
ID will be useful to us a little further, I recommend remembering it.
It is also highly recommended to make a backup copy of the GPG key. If the backup is encrypted — the loss of the key automatically means the loss of the ability to restore data from the backup. Let’s upload the key to save it in a safe place:
URL Format
Duplicity tries to maintain a standard URL format as much as possible. The generic format for a
URL is:
It is not recommended to expose the password on the command line since it could be
revealed to anyone with permissions to do process listings, however, it is permitted. Consider setting the environment variable FTP_PASSWORD instead, which is
supported by most, but not all backends. Regardless of its name, it can be used with other backends.
In protocols that support it, the path may be preceded by a single slash, ‘/path’, to represent a relative path to the target home directory, or preceded by
a double slash, ‘//path’, to represent an absolute filesystem path.
Ubuntu One
u1://host/volume_path
u1+http://volume_path
see also A NOTE ON UBUNTU ONE
Environment Variables
TMPDIR, TEMP, TMP
In decreasing order of importance, specifies the directory to use for temporary files (inherited from Python’s tempfile module).
Known Issues / Bugs
Hard links currently unsupported (they will be treated as non-linked regular files).
Bad signatures will be treated as empty instead of logging appropriate error message.
A Note on Symmetric Encryption and Signing
1. Setup gpg-agent properly. Use the option —use-agent and enter both passphrases (symmetric and sign key) in the gpg-agent’s dialog.
2. Use a PASSPHRASE for symmetric encryption of your choice but the signing key has an empty passphrase.
3. The used PASSPHRASE for symmetric encryption and the passphrase of the signing key are identical.
See Also
rdiffdir
, python
, rdiff
,
rdiff-backup
.
Options
Do not abort on attempts to use the same archive dir or remote backend to back up different directories. duplicity will tell you if you need this switch.
The archive directory. N OTE: This option changed in 0.6.0. The archive directory is now necessary in order to manage persistence for current and
future enhancements. As such, this option is now used only to change the location of the archive directory. The archive directory should not be deleted,
or duplicity will have to recreate it from the remote repository (which may require decrypting the backup contents).
When backing up or restoring, this option specifies that the local archive directory is to be created in path. If the archive directory is not
specified, the default will be to create the archive directory in ~/.cache/duplicity/.
The combination of archive directory and backup name must be unique in order to separate the data of different backups.
The interaction between the —archive-dir and the —name options allows for four possible combinations for the location of the archive dir:
neither specified (default) ~/.cache/duplicity/
hash-of-url
—archive-dir=/arch, no —name /arch/
hash-of-url
no —archive-dir, —name=foo ~/.cache/duplicity/foo
—archive-dir=/arch, —name=foo /arch/foo
(EXPERIMENTAL) Perform file uploads asynchronously in the background, with respect to volume creation. This means that duplicity can upload a volume while,
at the same time, preparing the next volume for upload. The intended end-result is a faster backup, because the local CPU and your bandwidth can be more
consistently utilized. Use of this option implies additional need for disk space in the temporary storage location; rather than needing to store only one
volume at a time, enough storage space is required to store two volumes.
Calculate what would be done, but do not perform any backend actions
When backing up, encrypt to the given public key, instead of using symmetric (traditional) encryption. Can be specified multiple times.
This option can only be used with —encrypt-key, and changes the path to the secret keyring for the encrypt key to filename This keyring is
not used when creating a backup. If not specified, the default secret keyring is
used which is usually located at .gnupg/secring.gpg
Convenience parameter. Same as —encrypt-key key —sign-key key.
Exclude all device files. This can be useful for security/permissions reasons or if rdiff-backup is not handling device files correctly.
Like —exclude-filelist but each line of the filelist will be interpreted according to the same rules as —include and —exclude.
Exclude directories if filename is present. This option needs to come before any other include or exclude options.
Exclude files on file systems (identified by device number) other than the file system the root of the source directory is on.
This option may be given in restore mode, causing only path to be restored instead of the entire contents of the backup archive. path should
be given relative to the root of the directory backed up.
Use passive (PASV) data connections. The default is to use passive, but to fallback to regular if the passive connection fails or times out.
Use regular (PORT) data connections.
Use the GIO backend and interpret any URLs as GIO would.
Try to ignore certain errors if they happen. This option is only intended to allow the restoration of a backup in the face of certain problems that would
otherwise cause the backup to fail. It is not ever recommended to use this option unless you have a situation where you are trying to restore from backup and
it is failing because of an issue which you want duplicity to ignore. Even then, depending on the issue, this option may not have an effect.
Please note that while ignored errors will be logged, there will be no summary at the end of the operation to tell you what was ignored, if anything. If
this is used for emergency restoration of data, it is recommended that you run the backup in such a way that you can revisit the backup log (look for lines
containing the string IGNORED_ERROR).
If you ever have to use this option for reasons that are not understood or understood but not your own responsibility, please contact duplicity maintainers.
The need to use this option under production circumstances would normally be considered a bug.
Allows you to specify a different mailbox. The default is «INBOX». Other languages may require a different mailbox than the default.
Allows you to pass options to gpg encryption. The options list should be of the form «opt1=parm1 opt2=parm2» where the string is quoted and the only
spaces allowed are between options.
Like —include-filelist, but read the list of included files from standard input.
Like —include-filelist but each line of the filelist will be interpreted according to the same rules as —include and —exclude.
Write specially-formatted versions of output messages to the specified file descriptor. The format used is designed to be easily consumable by other
programs.
Write specially-formatted versions of output messages to the specified file. The format used is designed to be easily consumable by other programs.
If not specified, the default value is a hash of the backend URL.
Do not use GnuPG to encrypt files on remote system. Instead just write gzipped volumes.
By default duplicity will print statistics about the current session after a successful backup. This switch disables that behavior.
Number of retries to make on errors before giving up.
Use the old filename format (incompatible with Windows/Samba) rather than the new filename format.
—rename orig new
Treats the path orig in the backup as if it were the path new. Can be passed multiple times. An example:
Allows you to pass options to the rsync backend. The options list should be of the form «opt1=parm1 opt2=parm2» where the option string is quoted
and the only spaces allowed are between options. The option string will be passed verbatim to rsync, after any internally generated option designating the
remote port to use. Here is a possibly useful example:
When using the Amazon S3 backend, create buckets in Europe instead of the default (requires —s3-use-new-style ). Also see the EUROPEAN S3
BUCKETS section.
Don’t use SSL for connections to S3.
This may be much faster, at some cost to confidentiality.
With this option, anyone who can observe traffic between your computer and S3 will be able to tell: that you are using Duplicity, the name of the bucket,
your AWS Access Key ID, the increment dates and the amount of data in each increment.
This option affects only the connection, not the GPG encryption of the backup increment files. Unless that is disabled, an observer will not be able to see
the file names or contents.
When operating on Amazon S3 buckets, use new-style subdomain bucket addressing. This is now the preferred method to access Amazon S3, but is not backwards
compatible if your bucket name contains upper-case characters or other characters that are not valid in a hostname.
Deprecated and ignored. The sftp/scp backend does no longer use an external scp client program.
Deprecated and ignored. The sftp/scp backend does no longer use an external sftp client program.
This option can be used when backing up, restoring or verifying. When backing up, all backup files will be signed with keyid key. When restoring,
duplicity will signal an error if any remote file is not signed with the given keyid. key should be an 8 character hex string, like AA0E73D2. Should be
specified only once because currently only one signing key is supported. Last entry overrides all other entries.
see also A NOTE ON SYMMETRIC ENCRYPTION AND SIGNING
Allows you to pass options to the ssh/scp/sftp backend. The options list should be of the form «-oopt1=parm1 -oopt2=parm2» where the option string
is quoted and the only spaces allowed are between options. Options must be given in the long option format described in ssh_config
. The
sftp/scp backend currently supports only one ssh option, IdentityFile like in this example:
If this option is specified, the names of the files duplicity writes will be shorter (about 30 chars) but less understandable. This may be useful when
backing up to MacOS or another OS or FS that doesn’t support long filenames.
Use this existing directory for duplicity temporary files instead of the system default, which is usually the /tmp directory. This option supersedes any
environment variable.
-ttime, —time time, —restore-time time
Specify the time from which to restore or list files.
Use char as the time separator in filenames instead of colon («:»).
Use seconds as the socket timeout value if duplicity begins to timeout during network operations. The default is 30 seconds.
If this option is specified, then —use-agent is passed to the GnuPG encryption process and it will try to connect to gpg-agent before it
asks for a passphrase for —encrypt-key or —sign-key if needed.
Note: GnuPG 2 and newer ignore this option and will always use a running gpg-agent if no passphrase was delivered.
If this option is specified, then the sftp/scp backend will use the scp protocol rather than sftp for backend operations. The default is to use sftp,
because it does not suffer from shell quoting issues like scp.
—verbosity level, -vlevel
Specify output verbosity level (log level). Named levels and corresponding values are 0 Error, 2 Warning, 4 Notice (default), 8 Info, 9 Debug
(noisiest).level may also bea character: e, w, n, i, da word: error, warning, notice, info, debug
The options -v4, -vn and -vnotice are functionally equivalent, as are the mixed/-vNotice and -vNOTICE.
Print duplicity’s version and quit.
Change the volume size to number Mb. Default is 25Mb.
Examples
Here is an example of a backup, using scp to back up /home/me to some_dir on the other.host
machine:
If the above is run repeatedly, the first will be a full backup, and subsequent ones
will be incremental. To force a full backup, use the full action:
Now suppose we accidentally delete /home/me and want to restore it the way it was
at the time of last backup:
Duplicity enters restore mode because the URL comes before the local directory. If we
wanted to restore just the file «Mail/article» in /home/me as it was three days ago into /home/me/restored_file:
duplicity —exclude /mnt —exclude /tmp —exclude /proc / file:///usr/local/backup
duplicity —include /home —include /etc —exclude ‘**’ / file:///usr/local/backup
Резервное копирование
На что обратить внимание:
Проверка состояния бэкапов на удаленном сервере:
NcFTP version is 3.2.5
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: Fri Sep 15 04:10:03 2017
Collection Status
——————
Connecting with backend: FTPBackend
Archive dir: /var/tmp/.duplicity/c9edc22d8a99b972fdf4bd3cec26e19f
Found 1 secondary backup chain.
Secondary chain 1 of 1:
————————-
Chain start time: Thu Aug 31 04:10:03 2017
Chain end time: Thu Sep 14 04:10:02 2017
Number of contained backup sets: 15
Total number of contained volumes: 252
Type of backup set: Time: Num volumes:
Full Thu Aug 31 04:10:03 2017 137
Incremental Fri Sep 1 04:10:02 2017 6
—————————-CUT—————————————-
————————-
Found primary backup chain with matching signature chain:
————————-
Chain start time: Fri Sep 15 04:10:03 2017
Chain end time: Fri Sep 29 04:10:03 2017
Number of contained backup sets: 15
Total number of contained volumes: 245
Type of backup set: Time: Num volumes:
Full Fri Sep 15 04:10:03 2017 142
Incremental Sat Sep 16 04:10:02 2017 8
—————————-CUT—————————————-
Incremental Fri Sep 29 04:10:03 2017 7
————————-
No orphaned or incomplete backup sets found.
Duplicity не позволяет помечать бэкап как устаревший автоматически (retention в терминологии “взрослых” систем). Чистить ненужные бэкапы придется в ручном режиме:
Эта команда удалит все бэкапы старше 4 последних полных бэкапов. В примере выше мы делали полный бекап каждые 2 недели, то есть duplicity удалит бэкапы старше 2 месяцев (8 недель). Если убрать ключ —force – duplicity найдет старые бэкапы, но не будет их удалять — только выведет на консоль. Забывать о чистке не рекомендуется — место на сервере для резервных копий может неожиданно кончиться и оставить вас без свежих бэкапов. Выясняется это весьма болезненно.
File Selection
duplicity accepts the same file selection options rdiff-backup does, including
—exclude, —exclude-filelist-stdin, etc.
is exactly the same as
because the include and exclude directives match exactly the same files, and the —include
comes first, giving it precedence. Similarly,
would backup the /usr/local/bin directory (and its
contents), but not /usr/local/doc.
Remember that you may need to quote these characters when typing them into a shell, so the shell does not interpret the globbing patterns before duplicity
sees them.
The —exclude pattern option matches a file iff:
Conversely, —include pattern matches a file iff:
matches /usr/local, /usr/local/lib, and /usr/local/lib/netscape. It is the same as —exclude /usr/local
—exclude ‘/usr/local/**’.
specifies that /usr, /usr/local, /usr/local/lib, and /usr/local/lib/netscape (but not /usr/doc) all be
backed up. Thus you don’t have to worry about including parent directories to make sure that included subdirectories have somewhere to go. Finally,
would match a file like /usR/5fOO/hello/there/world.py. If it did match
anything, it would also match /usr. If there is no existing file that the given pattern can be expanded into, the option will not match /usr.
The —include-filelist, —exclude-filelist, —include-filelist-stdin, and —exclude-filelist-stdin options also introduce file
selection conditions. They direct duplicity to read in a file, each line of which is a file specification, and to include or exclude the matching files. Lines
are separated by newlines or nulls, depending on whether the —null-separator switch was given. Each line in a filelist is interpreted similarly to the way
extended shell patterns are, with a few exceptions:
For example, if file «list.txt» contains the lines:
then «—include-filelist list.txt» would include /usr, /usr/local, and /usr/local/bin. It would exclude /usr/local/doc,
/usr/local/doc/python, etc. It neither excludes nor includes /usr/local/man, leaving the fate of this directory to the next specification condition. Finally,
it is undefined what happens with /var. A single file list should not contain conflicting file specifications.
The —include-globbing-filelist and —exclude-globbing-filelist options also specify filelists, but each line in the filelist will be
interpreted as a globbing pattern the way —include and —exclude options are interpreted (although «+ » and «- » prefixing is still allowed).
For instance, if the file «globbing-list.txt» contains the lines:
Then «—include-globbing-filelist globbing-list.txt» would be exactly the same as specifying «—include dir/foo —include dir/bar
—exclude **» on the command line.
Finally, the —include-regexp and —exclude-regexp allow files to be included and excluded if their filenames match a python regular
expression. Regular expression syntax is too complicated to explain here, but is covered in Python’s library reference. Unlike the —include and
—exclude options, the regular expression options don’t match files containing or contained in matched files. So for instance
Actions
Delete the extraneous duplicity files on the given backend. Non-duplicity files, or files in complete data sets will not be deleted. This should only be
necessary after a duplicity session fails or is aborted prematurely. Note that —force will be needed to delete the files rather than just list them.
Summarize the status of the backup repository by printing the chains and sets found, and the number of volumes in each.
Indicate full backup. If this is set, perform full backup even if signatures are available.
If this is requested an incremental backup will be performed. Duplicity will abort if old signatures cannot be found. The default is to switch to full
backup under these conditions.
Lists the files currently backed up in the archive. The information will be extracted from the signature files, not the archive data itself. Thus the whole
archive does not have to be downloaded, but on the other hand if the archive has been deleted or corrupted, this command may not detect it.
Delete all backups sets that are older than the count:th last full backup (in other words, keep the last count full backups and associated
incremental sets). count must be larger than zero. A value of 1 means that only the single most recent backup chain will be kept. Note that
—force will be needed to delete the files rather than just list them.
Delete incremental sets of all backups sets that are older than the count:th last full backup (in other words, keep only old full backups and not their
increments). count must be larger than zero. A value of 1 means that only the single most recent backup chain will be kept intact. Note that
—force will be needed to delete the files rather than just list them.
Enter verify mode instead of restore. If the —file-to-restore option is given, restrict verify to that file or directory. duplicity will exit with a
non-zero error level if any files are different. On verbosity level 4 or higher, log a message for each file that has changed.
Name
duplicity — Encrypted backup using rsync algorithm
A Note on European S3 Buckets
duplicity will create a new bucket the first time a bucket access is attempted. At this point, the bucket will be created in Europe if
—s3-european-buckets was given. For reasons having to do with how the Amazon S3 service works, this also requires the use of the
—s3-use-new-style option. This option turns on subdomain based bucket addressing in S3. The details are beyond the scope of this man page, but it is
important to know that your bucket must not contain upper case letters or any other characters that are not valid parts of a hostname. Consequently, for
reasons of backwards compatibility, use of subdomain based bucket addressing is not enabled by default.
Note that you will need to use —s3-use-new-style for all operations on European buckets; not just upon initial creation.
You only need to use —s3-european-buckets upon initial creation, but you may may use it at all times for consistency.
Further note that when creating a new European bucket, it can take a while before the bucket is fully accessible. At the time of this writing it is unclear
to what extent this is an expected feature of Amazon S3, but in practice you may experience timeouts, socket errors or HTTP errors when trying to upload files
to your newly created bucket. Give it a few minutes and the bucket should function normally.
A Note on Imap
The from_address_prefix may be specified (and probably should be). The text will be used as the «From» address in the IMAP server. Then on a restore
(or list) command the from_address_prefix will distinguish between different backups.
Проверка и восстановление
Посмотрим файлы, которые у нас есть в бэкапе:
NcFTP version is 3.2.5
Local and Remote metadata are synchronized, no sync needed.
Last full backup date: Sat Sep 29 04:10:03 2017
Mon Oct 2 04:10:02 2017 .
Mon Aug 29 21:07:04 2016 PG_VERSION
Mon Oct 2 04:10:02 2017 backup_label
————————CUT———————————
Команда выше покажет состояние на момент последнего бэкапа. Чтобы получить информацию из более старых бэкапов, нужно использовать ключ -t. К примеру, -t6D вернет информацию о бэкапе, сделаном 6 дней назад.
Восстановление данных выглядит ровно так же, как бэкап, нужно просто поменять местами source (откуда брать данные) и destination:
Operation and Data Formats
This section describes duplicity’s basic operation and the format of its data
files. It should not necessary to read this section to use duplicity.
The files used by duplicity to store backup data are tarfiles in GNU tar format. They can be produced independently by rdiffdir
. For
incremental backups, new files are saved normally in the tarfile. But when a file changes, instead of storing a complete copy of the file, only a diff is
stored, as generated by rdiff
. If a file is deleted, a 0 length file is stored in the tar. It is possible to restore a duplicity archive
«manually» by using tar and then cp, rdiff, and rm as necessary. These duplicity archives have the extension difftar.
Both full and incremental backup sets have the same format. In effect, a full backup set is an incremental one generated from an empty signature (see
below). The files in full backup sets will start with duplicity-full while the incremental sets start with duplicity-inc. When restoring,
duplicity applies patches in order, so deleting, for instance, a full backup set may make related incremental backup sets unusable.
In order to determine which files have been deleted, and to calculate diffs for changed files, duplicity needs to process information about previous
sessions. It stores this information in the form of tarfiles where each entry’s data contains the signature (as produced by rdiff) of the file instead
of the file’s contents. These signature sets have the extension sigtar.
Signature files are not required to restore a backup set, but without an up-to-date signature, duplicity cannot append an incremental backup to an existing
archive.
To save bandwidth, duplicity generates full signature sets and incremental signature sets. A full signature set is generated for each full backup, and an
incremental one for each incremental backup. These start with duplicity-full-signatures and duplicity-new-signatures respectively. These
signatures will be stored both locally and remotely. The remote signatures will be encrypted if encryption is enabled. The local signatures will not be
encrypted and stored in the archive dir (see —archive-dir ).
Description
Duplicity incrementally backs up files and directory by encrypting tar-format volumes with
GnuPG and uploading them to a remote (or local) file server. Currently local, ftp, sftp/scp, rsync, WebDAV, WebDAVs, Google Docs, HSi and Amazon S3 backends
are available. Because duplicity uses librsync, the incremental archives are space efficient and only record the parts of files that have changed since the
last backup. Currently duplicity supports deleted files, full Unix permissions, directories, symbolic links, fifos, etc., but not hard links.
If you are backing up the root directory /, remember to —exclude /proc, or else duplicity will probably crash on the weird stuff in there.
A Note on Ubuntu One
Connecting to Ubuntu One requires that you be running duplicity inside of an X
session so that you can be prompted for your credentials if necessary by the Ubuntu One session daemon.

