Creating Encrypted FTP Backups With duplicity And ftplicity On Debian Lenny - Page 2

5 Automatic Backups With ftplicity

Because duplicity asks for a GnuPG password everytime we use it, it's hard to use it for automatic backups (e.g. via cron). Fortunately there's ftplicity, a duplicity wrapper script, which allows us to call duplicity without being asked for a password.

First we generate a GnuPG key that ftplicity will use (so that we don't have to type in a password anymore):

gpg --gen-key

server2:/home/exampleuser# gpg --gen-key
gpg (GnuPG) 1.4.6; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Please select what kind of key you want:
   (1) DSA and Elgamal (default)
   (2) DSA (sign only)
   (5) RSA (sign only)
Your selection? <-- ENTER
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
 <-- ENTER
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
 <-- ENTER
Key does not expire at all
Is this correct? (y/N)
 <-- y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <>"

Real name:
 <-- your name, e.g. Falko Timme
Email address: <-- your email address, e.g.
You selected this USER-ID:
    "Falko Timme <>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
 <-- O
You need a Passphrase to protect your secret key. <-- Type in your desired password (twice to confirm it)

Now the key will be generated. It's a good idea to open a second console and type some letters so that the random number generator can gain enough entropy:

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 
7C6E958B marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   1024D/7C6E958B 2007-12-10
      Key fingerprint = 1FDC 60FB 8A27 90D8 553C  3C3E 8E1F 66F7 7C6E 958B
uid                  Falko Timme <>
sub   2048g/F1BB98F4 2007-12-10


I've highlighted the key ID (7C6e958B) because we'll need it in a moment.

Next we download ftplicity:

cd /tmp
tar xvfz 0613-216.tar.gz
cp ftplicity-1.2/ftplicity /usr/local/bin

Now we create /root/.ftplicity/conf. It has the following variables:

  • GPG_KEY: the ID of our GnuPG key;
  • GPG_PW: the password we typed in when we created the GnuPG key;
  • ZIEL: the backup server (incl. the FTP username);
  • ZIEL_PW: the FTP password in the backup server;
  • QUELLE: the source directory (i.e., the directory to be backed up);
  • HOECHSTALTER: the age of the oldest backup; older backups will be deleted;
  • VERBOSITY: amount of information displayed on the screen by ftplicity;
  • TEMP_DIR: a directory for temporary files; when you restore a backup, this directory must at least have enough space for the biggest file in the backup.

vi /root/.ftplicity/conf

# Daten fuer GPG-Schluessel
# Zugangsdaten fuer FTP-Server (URL-Format)
# Basisverzeichnis fuers Backup
# aeltester Wiederherstellungszeitpunkt
# Ausfuehrlichkeit der Bildschirmausgaben (9 fuer Fehlersuche)
# Verzeichnis fuer temporaere Dateien. Beim Restore muss dort
# mindestens Patz fuer die groesste Datei im Backup sein

Afterwards we change the permissions of the file so that only root has read and write permissions:

chmod 600 /root/.ftplicity/conf

We can now create three other files, although that is totally optional:

  • /root/.ftplicity/exclude: contains a list of directories to be excluded from the backup (one directory per line);
  • /root/.ftplicity/pre: contains command(s) to be executed prior to the backup (e.g. create a MySQL database dump);
  • /root/.ftplicity/post: contains command(s) to be executed after the backup.

Here's a sample /root/.ftplicity/exclude and /root/.ftplicity/pre file (the syntax of /root/.ftplicity/post is the same as in /root/.ftplicity/pre):

vi /root/.ftplicity/exclude


chmod 600 /root/.ftplicity/exclude

vi /root/.ftplicity/pre

/usr/bin/mysqldump –-all-databases -u root -pyourrootsqlpassword > /home/exampleuser/db.sql

(It should be noted that the database gets locked during the creation of SQL dump; this might not be an issue for a small web site, but can be a problem for high-traffic web sites - your visitors won't be able to access database-driven pages during mysqldump. Here's a link to an interruption-free MySQL backup method: How To Back Up MySQL Databases Without Interrupting MySQL)

/root/.ftplicity/pre must be executable (as well as /root/.ftplicity/post if you choose to create one):

chmod 700 /root/.ftplicity/pre

As I said before, you only need /root/.ftplicity/conf; the other files are optional.

Now ftplicity is ready to be used; to create our backup, we simply run

ftplicity backup

If all goes well, you won't be prompted for a password:

server2:~# ftplicity backup
NcFTP version is 3.2.1
Reading globbing filelist /root/.ftplicity/exclude
Last full backup date: Tue Mar 30 17:11:19 2010
--------------[ Backup Statistics ]--------------
StartTime 1269964060.17 (Tue Mar 30 17:47:40 2010)
EndTime 1269964060.25 (Tue Mar 30 17:47:40 2010)
ElapsedTime 0.08 (0.08 seconds)
SourceFiles 44
SourceFileSize 1576302 (1.50 MB)
NewFiles 0
NewFileSize 0 (0 bytes)
DeletedFiles 0
ChangedFiles 0
ChangedFileSize 0 (0 bytes)
ChangedDeltaSize 0 (0 bytes)
DeltaEntries 0
RawDeltaSize 0 (0 bytes)
TotalDestinationSizeChange 1038 (1.01 KB)
Errors 0


To automate the backups, we can create a cron job (I create two cron jobs, one that runs daily and creates incremental backups, and one that runs once a month, creates a full backup and deletes old files):

crontab -e

# run the (incremental) backup each night at 03:23h
23 3 * * * /usr/local/bin/ftplicity backup
# do a full backup once per month & delete old backups
47 4 1 * * /usr/local/bin/ftplicity full && /usr/local/bin/ftplicity purge –-force


6 Restoring A Backup With ftplicity

Of course, you can use ftplicity also to restore a backup (again, you won't be asked for a password). The syntax is very easy:

ftplicity restore /home/exampleuser

You can take a look at the ftplicity help to learn what other options you have:

ftplicity --help

server2:~# ftplicity --help

Usage: ftplicity <command> [<options> ...]

  backup:    incremental backup
  full:      force full backup
  list:      list all files in the backup
  status:    information on backup sets
  verify:    list files changed since latest backup
  purge [--force]:
             list obsolete backup archives [and delete them]
  cleanup [--force]:
             purge incomplete backup archives (after crashed backup)
  restore <destination path> [<age>]:
             restore backup to <destination path> [as of <age>]
  fetch <file/directory> <destination> [<age>]
             restore single file/directory (see example)

  list and delete obsolete backup archives:
    ftplicity purge --force
  restore latest backup to /mnt:
    ftplicity restore /mnt
  restore /etc/passwd from 4 days ago to /root/pw:
    ftplicity fetch etc/passwd /root/pw 4D
    (see "man duplicity", section TIME FORMATS)

files in /root/.ftplicity
  conf      main configuration file
  pre       will be executed befor backups
  post      will be executed after backups
  gpgkey    contains a copy of the used GPG key
  exclude   list of excluded files and directories
            (see "man duplicity", section FILE SELECTION)



7 Links

Share this page:

5 Comment(s)

Add comment


From: Anonymous at: 2010-08-09 19:27:45

ftplicity wont work with the newer version of duplicity

 root@master / # ftplicity backup
There has been a fatal error:
  Unsupported duplicity version 0.6.08b. 0.4.11 is recommended.

From: Jims ftp storage at: 2010-08-10 08:45:12

Making sure your system is up to date first is vital for avoiding compatibility issues and a few bugs/annoyances later on. Trust me, I've been there!

From: Maik Holtkamp at: 2011-08-24 14:05:40

I modified the script (which ftplicity), as follows:

line 36:

to set the squeeze Version as recommended.

line 249:


to make sure the actual version of duplicty would not hit by the following case:

        error "$(getstr DuplVersUnsup)"

Seems to work. HTH

From: Maik Holtkamp at: 2011-08-25 08:04:54

Sorry, but some hours later I have to admit:

If this error comes up because you updated lenny to squeeze, don't follow above given workaround, even if it works!

Squeeze offers duply the advancment of ftplicity. It will work with the duplicitiy version that comes with squeeze without any hacks, of course. One major difference is that duply offers so called profiles, so you can create and use different configs if you have different tasks. If you don't need it just create a default profile by whatsoever name, let's say foobar. Then do:

# apt-get install duply
# duply create foobar
# for i in ~/.duply/foobar/*; do mv $i ~/.duply/foobar/$i.original; done
# mv ~/.ftplicity/* ~/.duply/foobar/
# duply foobar backup

If you are using cronjobs or wraper scripts make sure to do a

s/ftplicity/duply foobar/g

on them. Have a look at the man page, there are quite some improvments made for duply e.g. PRE/POST run scripting.

Last not least one more general hint:

Bevore starting hacking scripts you hardly understand, just consult your $DISTRIBUTION_TOOLS:

# apt-cache search ftplicity
duply - easy to use frontend to the duplicity backup system

From: bts_freak at: 2010-10-08 06:39:35

Anyone know how I can specify either multiple SOURCE Files or multiple profiles? Otherwise, this is a nice toy, but not really usefull...