Howto backup your “dedicated server” to a foreign FTP server

June 11, 2009

In my last post I’ve written a howto on installing Xen and OpenVZ on a dedicated root server at a locally well know server ISP. This post is now about the method I use to backup this server on the ISP provided FTP space. The backup solution I use provides following:

  • Full backup and restore of the whole server or single files
  • GnuPG encryption of the data on the FTP server
  • full and incremental backup
  • open source and free
  • simple setup and usage

The base of the backup system is duplicity, but I use ftplicity as front-end which makes the interface easier to handle in this special case. As the hardware node of the server is running under CentOS 5, this howto is centered around it, but the basic idea is the same for any distribution.

  1. Repository: We need to add the EPEL5 repository by calling

    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm

    Info: Replace x86_64 with i386 if you’ve a 32bit system.
  2. Packages: I did following to update and install the required packages:

    yum update
    yum install duplicity python-GnuPGInterface
  3. Bug fixing: There is a small bug in the duplicity package (duplicity-0.5.06-1.el5) which leads to some unlovely error messages. You can and should correct them like this:

    wget http://savannah.nongnu.org/bugs/download.php?file_id=17304
    patch /usr/bin/duplicity duplicity-sys-exit.patch

    If the patching worked you should get a output like this:

    patching file /usr/bin/duplicity
    Hunk #1 succeeded at 589 (offset 2 lines).
  4. ftplicity install: There is currently no package for ftplicity, but as it consists basically only of one bash script that doesn’t really matter. Just use following commands

    mkdir ftplicity
    cd ftplicity/
    wget http://surfnet.dl.sourceforge.net/sourceforge/ftplicity/ftplicity_1.4.2.1.tgz
    tar xzf ftplicity_1.4.2.1.tgz
    cp ftplicity_1.4.2.1/ftplicity /usr/local/sbin/

    to install it.
  5. ftplicity configuration:Everything is now installed and we only need to configure it. The shell script creates its own default config if called like this: ftplicity [profilename] create. Choose a profile name, as ftplicity allows you to use more than one profile (e.g. to backup different stuff to different ftp servers). Now change into the directory /root/.ftplicity/[profilename].
    You need now to create a gpg key with gpg --gen-key – use the default options and a complicated pass-phrase. Continue with editing the file conf, by at least setting following variables:

    GPG_KEY= to the ID of the key just generated
    GPG_PW= to the pass-phrase you just entered
    TARGET= to your backup server, use a subdirectory and not / as you may want to backup a second profile or server later and create that subdirectory
    TARGET_PW= to the ftp password
    SOURCE='/' # as we backup everything

    Take also a look at the other parameters but you’re not required to change them. As we’re backing up the whole server it is necessary to exclude some directories. To accomplish this you need to create a file exclude in the profile directory which contains at least following lines.

    /dev
    /proc
    /sys
    /tmp
    /var/cache
    /var/tmp
    /var/run

    As we’re using the server with OpenVZ we also add following lines:

    /var/spool
    /vz/root
    /vz/private/*/proc
    /vz/private/*/sys
    /vz/private/*/dev
    /vz/private/*/var/cache/apt/archives
    /vz/private/*/var/lib/courier/allfilters
    /vz/private/*/var/lib/dcc
    /vz/private/*/var/lib/apache2/fastcgi
    /vz/private/*/tmp
  6. first backup: Type ftplicity profilename backup to make your first (=full) backup. You should not get any exceptions or error message if you’ve configured every correctly.
  7. automatic backup As you see at the first backup, ftplicity is verbosely – this is good if an error occurs but I don’t like an email every day if all worked. Therefore I’ve written the python script ftplicity.py, which parses the output of the shell script and only sends (but than the full verbose output) an email (via cron) to me if something went wrong. Copy the script to /usr/local/sbin and set the execute flag.Now you only need to edit the crontab with following command: crontab -e and place some lines like this there.
    5 9 * * * /usr/local/sbin/ftplicity.py profilename backup
    6 17 1 * * /usr/local/sbin/ftplicity.py profilename full && /usr/local/sbin/ftplicity.py profilename purge --force && /usr/local/sbin/ftplicity.py hetzner purge-full

That’s it – quite easy? Anyway take a look at ftplicity usage which shows you these usage examples:

  • create profile ‘humbug’: ftplicity humbug create (now edit the resulting conf file)
  • backup ‘humbug’ now: ftplicity humbug backup
  • list available backup sets of profile ‘humbug’: ftplicity humbug status
  • list and delete obsolete backup archives of ‘humbug’: ftplicity humbug purge --force
  • restore latest backup of ‘humbug’ to /mnt/restore: ftplicity humbug restore /mnt/restore
  • restore /etc/passwd of ‘humbug’ from 4 days ago to /root/pw: ftplicity humbug fetch etc/passwd /root/pw 4D (see “man duplicity”, section TIME FORMATS)

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. I do consider all of the concepts you have presented on your post.
    They are very convincing and will certainly work. Still, the posts are too short for newbies.
    May you please extend them a little from next time?
    Thanks for the post.

    Comment by Jefferey — February 11, 2016 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Powered by WordPress
Entries and comments feeds. Valid XHTML and CSS. 36 queries. 0.058 seconds.