ruplicity 0.2.0

Library to read duplicity backups
Documentation
## Useful links

* tutorial on using FUSE filesystem in rust [part I]http://zsiciarz.github.io/24daysofrust/book/day15.html and [part II]http://zsiciarz.github.io/24daysofrust/book/day16.html and related [source code]https://github.com/zsiciarz/24daysofrust/blob/master/src/day15.rs;
* [tempfile library]https://www.reddit.com/r/rust/comments/32n864/tempfile_temporary_file_library/;
* how to restore duplicity backups in the [worst case]https://wiki.gnome.org/Apps/DejaDup/Help/Restore/WorstCase;
* [man rdiff]http://linux.die.net/man/1/rdiff.

## Duplicity

To restore a backup without passphrase into a directory use this command:

```
duplicity restore --no-encryption file://<absolute-path-of-backup> <path-to-restore>
```

To backup incrementally from an existing backup and a source directory:

```
duplicity incremental --no-encryption <source-dir> file://<absolute-path-of-backup>
```

To list current files in backup:

```
duplicity list-current-files --no-encryption file://<absolute-path-of-backup>
```

To list files of a given time:

```
duplicity list-current-files --time <time> --no-encryption file://<absolute-path-of-backup>
```

See "Time formats" section for the format of `<time>` string.

To list all the backup snapshots contained in a directory:

```
duplicity collection-status --no-encryption file://<absolute-path-of-backup>
```

### 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](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:

1. the string "now" (refers to the current time);
2. a sequences of digits, like "123456890" (indicating the time in seconds after the epoch);
3. a string like "2002-01-25T07:00:00+02:00" in datetime format;
4. an interval, which is a number followed by one of the characters s, m, h, D, W, M, or Y (indicating seconds, minutes, hours, days, weeks, months, or years respectively), or a series of such pairs. In this case the string refers to the time that preceded the current time by the length of the interval. For instance, "1h78m" indicates the time that was one hour and 78 minutes ago. The calendar here is unsophisticated: a month is always 30 days, a year is always 365 days, and a day is always 86400 seconds;
5. 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.

## Duplicity file format

### Filenames

File extensions are used to determine if the file is compressed or encrypted:

* `.gz` is a compressed file;
* `.gpg` is an encrypted file.

File names are used to define the type, the time, the volume and the relationships between snapshots. Those files must obey certain regular expressions to be considered part of a duplicity backup.


### Signatures

A signature file is a tar file (compressed and/or encrypted) with a defined structure.
Every file in the tar is in one of the following folders:

* `signature`;
* `snapshot`;
* `deleted`.

Any other folder is ignored.

To determine which files belongs to a given snapshot, consider and sort the signature files up to the desired date. The algorithm works as follows:

1. open the tar files of all the signature files, and iterate over their first file (they are alphabetically ordered);
2. sort the resulting filenames by name and number of signature file; in this way, when the filenames are the same, the last signature file wins;
3. yield the top element of this list;
4. advance the iterators on the signature files; if a signature files comes to an end, remove it;
5. collect the resulting filenames;
6. go to point 2 if there are still filenames to consider.

### Signature file format

Signatures are generated by [librsync](https://github.com/librsync/librsync). See [mksum.c](https://github.com/librsync/librsync/blob/54e505667257fd1ea786454bea390784d817123c/mksum.c).

Duplicity uses md4 type signatures, because the header starts with: 0x72730136. The file format is the following:

- Header
  - 32b BE magic number (0x72730136 for MD4);
  - 32b BE block length (duplicity uses different block lengths);
  - 32b BE strong sum length (16 for native MD4, 8 for duplicity);
- Block *
  - 32b BE weak sum;
  - [strong sum length]B BE? strong sum;

BE stands for Big Endian. There is only one header and then one block for each file block.