Using lftp for automated backups

Due to a hard drive failure recently, I discovered an excellent ftp client called lftp. I needed a way to backup the important directories such as /home /etc /var/www etc. quickly before the drive failed completely. I had never used any ftp client in the past for automated backups because I couldn’t find one that did what I wanted.

I needed a way of mirroring local directories to a remote backup and it had to delete files that no longer existed locally, a trivial task for something like rsync but finding a FTP client that provided this proved unsuccessful until I came across lftp.

According to Wikipedia:

lftp is a command-line file transfer program (FTP client) for UNIX and Unix-like systems. It was written by Alexander Lukyanov, and is made available under the GNU General Public License.

lftp is available on most major Linux distributions and can be installed through your systems package manager.

Once you have it installed, you can launch it by running:

lftp username@hostname

You’ll be prompted for a password if required. You can do all the usual commands such as ls, cd, mkdir etc. and you can find out more commands by typing help.

The command that is of most interest to me is the mirror command. It mirrors a remote directory recursively ie. it copies the directories contents including sub directories. The mirror command itself takes a number of parameters:

-c, --continue          continue a mirror job if possible
-e, --delete            delete files not present at remote site
-s, --allow-suid        set suid/sgid bits according to remote site
    --allow-chown       try to set owner and group on files
-n, --only-newer        download only newer files (-c won't work)
-r, --no-recursion      don't go to subdirectories
-p, --no-perms          don't set file permissions
    --no-umask          don't apply umask to file modes
-R, --reverse           reverse mirror (put files)
-L, --dereference       download symbolic links as files
-N, --newer-than FILE   download only files newer than the file
-P, --parallel[=N]      download N files in parallel
-i RX, --include RX    include matching files
-x RX, --exclude RX    exclude matching files
-I GP, --include-glob GP        include matching files
-X GP, --exclude-glob GP        exclude matching files
-v, --verbose[=level]   verbose operation
    --use-cache         use cached directory listings
--Remove-source-files   remove files after transfer (use with caution)
-a                      same as --allow-chown --allow-suid --no-umask

Care should be taken when using the mirror command because by default the command mirrors a remote directory to the local file system so when you think you’re copying local files to a remote location, you’re actually overwriting your local files with the files from the remote server!
To mirror files from the local file system to the remote, the -R parameter should be passed to the mirror command:

mirror -R /path/to/local/ /path/to/remote/

You can delete files on the remote server that no longer exist on the local file system by passing the -e parameter to the command above:

mirror -Re /path/to/local/ /path/to/remote/

As from what can be seen above, there is a substantial number of options that can be passed to the mirror command. The only extra argument I use is –use-cache to speed up the transfer process.

You can run lftp from a bash script like so:

#!/bin/bash
lftp -u username,password ftphost << EOF
mirror -Re --use-cache /home/ /backup/
mirror -Re --use-cache /etc/ /backup/
mirror -Re --use-cache /var/www/ /backup/
quit 0
EOF

 

Then, all you have to do is add this script as a cron job and you’re good to go!

SSL routines SSL3_ACCEPT unsafe legacy renegotiation disabled

After moving this website completely to HTTPS, it would no longer load in Internet Explorer. IE’s well known for having compatibility issues with websites that other browsers do not have but this was different from what I had ever seen before.

IE didn’t display anything useful to describe what error was encountering, it put the issue down to connection issues, the same error you’d receive if you lost your internet connection. Not useful at all for diagnosing the problem.

I then looked at the Apache error logs and noticed the following errors being logged every time the site was accessed from IE:

[Fri Dec 30 22:04:09 2011] [error] [client 194.46.255.70] Re-negotiation request failed
[Fri Dec 30 22:04:09 2011] [error] SSL Library Error: 336068946 error:14080152:SSL routines:SSL3_ACCEPT:unsafe legacy renegotiation disabled

Google didn’t give me any help worthwhile so I had to resort to commenting out the SSL directives in the virtual host configuration file. I eventually narrowed it down to the following directive:

SSLVerifyClient optional

Disabling that directive made the site load successfully in Internet Explorer. The SSLVerifyClient directive sets the certificate verification level for the client authentication. I’m not sure why Internet Explorer doesn’t like this because my certificate is from a valid issuing authority. I guess it’s just one more thing that doesn’t work in IE…

Ferguson 20 Workshop Manual

Here is a link to download a full workshop manual for a Ferguson 20 Petrol/Diesel

Click here to download

GPG Public Key

My GPG Public Key is available here or on the major key servers

GPG Key Fingerprint: 5C76 E008 6321 5961 7417  D591 65E8 D3EA 2AFD E92C

 

Logic in Computer Science 2nd. Edition – Solutions

I purchased Logic in Computer Science 2nd Edition recently in preparation for an exam I have soon. This book has proven to be very useful, it’s full of useful information and exercises to complete. However, one caveat I have with the book is that they don’t provide completed solutions to the exercises. This seems to be a common trait in the majority of Computer Science books that I’ve read recently and it makes very difficult to know whether your solutions are correct or incorrect.

After some time searching, I found the official solution book to accompany this text, it contains fully completed exercises from the book.

Here’s a link to download a PDF version of the solution book: http://www.mediafire.com/?hkz2ld22l6dk8cb

Hopefully it helps you as much as it has helped me!