Aug 06

Backup 1Whether you are a web host, an IT professional or a hobbyist, if you have one or more headless Linux servers, backups are one of your main concerns. And incremental backups are your friends.
Amazon S3 (http://www.amazon.com/aws) offers a very interesting storage solution, especially since they lowered their already low rates.
It even comes with a tool called ’s3sync’ that works a bit like rsync.
Unfortunately it only works ‘a bit’ like rsync; it does not check if a remote file with the same timestamp and/or checksum exists, and it ends up using up much more bandwidth than you originally planned for.
This could be avoided if S3 supported rsync; unfortunately it does not.

An ideal solution would be a local rsync, which would be smart about copying files.
No problem! This can be achieved by mounting an S3 bucket as a local disk; here is how.

In this tutorial, I am going to refer to your headless web server as your ‘Linux box’. So, if your local box also runs Linux, please bear with me: I am not talking about this box!

Here we go:

JunglediskDownload the USB key version of Jungledisk from http://www.jungledisk.com/download.shtml and run it on your local machine. It does not matter if you’re running Windows, OS X or Linux. All three systems are supported. Jungledisk will create a configuration file called ‘jungledisk-settings.ini’
If you need to modify this file, run junglediskmonitor and modify your settings.

Download the Linux version of Jungledisk, expand the archive and copy ‘jungledisk’ to its own directory on your Linux box.
Copy your local jungledisk-settings.ini to your Linux box in the same directory as ‘jungledisk’. You do not need to copy and run ‘junglediskmonitor’ on that box, since all it would do is modify the .ini file.

Everyting from this point on is going to happen on your Linux box.

If you do not have Fuse, download it from http://sourceforge.net/project/showfiles.php?group_id=121684&package_id=132802
Expand the package, go to the new Fuse directory.
Type:
./configure --enable-lib
make && make install

If you forget --enable-lib, the dynamic library will not be created.

Alternatively you could use Coda instead of Fuse but it tends to come with your OS and you may end up using a wrong version of Coda with Davfs. And I like the flexibility of Fuse. Research it a little bit: installing Fuse buys you much more than what is covered in this tutorial.

Make and install libneon. You may already have a neon package installed. If so, you can try to proceed without downloading a newer version. If you systematically experience ‘mount’ - cf below - complaining about ‘invalid URL’, I recommend upgrading libneon.
Get it at http://www.webdav.org/neon/

Expand, go to the new directory, type:
./configure
make && make install

Make and install davfs. Get it at http://dav.sourceforge.net/
Actually, you may find a binary that perfectly suits your box and not even need to build it. Otherwise, type:
./configure
make && make install

Let’s create a user/group for davfs:
groupadd davfs2
useradd davfs2 -g davfs2

You now have all the pieces required. Let’s get crankin’:

Run ‘jungledisk’:
./jungledisk

You are likely to have a text-mode browser, either ‘lynx’ or ‘links’. Let’s pick one -in my case: ‘links’
links http://localhost:2667

If it displays an XML header rather than rejecting your connection, then jungledisk is running correctly.

Time to mount your disk. Here is how:
mkdir /mnt/J # (or any other directory you wish to use)
mount http://localhost:2667 /mnt/J --nolock -t davfs

The --nolock may seem a bit superstitious but in my experience mounting a remote FS without it can lead to catastrophic crashes.

You now have an unlimited disk drive mounted at /mnt/J/

If all this works correctly, you can now start thinking of mounting your disk at boot-up time.
First, you need to start ‘jungledisk’ everytime. Either create a start-up script in /etc/init.d and use chkconfig or if you wish to keep things simple, add a call to jungledisk at the end of your /etc/rc.d/rc.local. I have to check that the latter works though as I believe that Linux will try to mount your disk before calling rc.local

And finally, let’s make sure that we have an entry in /etc/fstab:
http://localhost:2667 /mnt/J davfs noauto,user 0 0

That’s all!

Backup 2Oh, wait. Right. What about backups?
As I wrote earlier, rsync remains your best bet. Here is how to run it:

mkdir -p /mnt/J/home/1
rsync -aHx --numeric-ids --no-whole-file --size-only /home/ /mnt/J/home/1/

This example shows how to perform smart backups of your /home directory; the reason why I am pushing this backup to a directory called ‘1′ is that I am performing real incremental backups with automated backup rotation.
If you have questions about it, I will write another tutorial where I explain how to use hard links to rotate backups without wasting disk space. But in the meantime, do not let that ‘1′ scare you.

So, what’s this then?
--no-whole-file is extremely important: rsync thinks that you are copying your files to a local disk and decides to favour local speed as opposed to saving on bandwidth usage. This can be very bad. This parameter forces it to be smarter than that.
-a tells rsync to use an ‘archive’ mode where all important files information is preserved
-H allows us to preserve hard links - not covered by ‘a’
-x is important as well: you will not end up creating back ups of whatever remote devices you have mounted locally
-size-only new: suggested by, I guess, Eric Johnson, is important for the reasons enumerated in his comments below (mtexte)

Eric also suggests using ‘inplace but I am not so sure about that yet.

OK, *now* that’s all (for now!)

Sphere: Related Content

Aug 02

Sandro Groganz gives an interesting response to Matt Mullenweg’s taking PHP 5 and Zend to task.
I find his post interesting because he compares Php5 to Java, unlike the rest of us who are focused on Ruby and other sexy beasts.
As a Java programmer myself -and one of the many Java people dazzled by Ruby- I have a lot of sympathy for his take. After all, from where I stand, Php5 is simply an attempt at replicating everything that Zend likes about Java. I wonder if the idea was to attract Java programmers but if so, it shows a serious lack of understanding of what we like. Java developers are not looking for a laundry list of features; if we were simply looking for a lightweight version of Java, Groovy is all we need, thank you. Rails, on the other hand, really appeals to a professional developer’s mind with its elegant constructs such as built-in iterators and its community.

I am among the people who believe that Php5 is a mistake. Php4 was perfect to develop lightweight projects that require good performance while maintaining an iterative development model. I also think of myself as a Php4 developer when necessary just like I know that I can whip up a shell script when I need something done very quickly.

I have used Php4 for years. Then, Php5 came along, making promises of object orientation that would allow me to write code about as complex as my Java code. OK, so what benefit am I getting from using this new language? (From Matt Mullenweg’s post: “I wonder if PHP 5+ should be called something other than PHP” - aye!)

I use Php a lot, for Clic!Dev, nextBBS and other very demanding projects. Sorry to say, but the last thing I need is an interpreted object-oriented language. If I am forced to move to Php5, one of two things will happen:
1. I will code in Php5 the exact same way I am coding right now in Php4, ie using a minimum of object orientation
2. Or I will decide to bite the bullet and recode everything using a language that doesn’t suffer an identity crisis

I wish Drupal and other members of the ‘Pure Php5 Movement’ good luck and I think that it’s a good idea for projects this size to implement the best development practices, however I cannot help but think that the only reason why they are doing so in Php is mainly because nobody wants to can thousands of lines of legacy code.

Your feedback is welcome. Actually I would be more than happy to be proven wrong on this topic!

Sphere: Related Content