quick easy backups on linux

Wednesday 23rd January 2008 22:45

There are a lot of backup options out there for linux, and everyone seems to want to roll their own, which is understandable when there are just so many different environments and setups.

I have a fairly large database of photos, which I really needed to keep backed up, but obviously this will work on any type of file.

First things first, I suggest backing up to an external USB drive, I simply used a spare 250gb drive, and a USB caddy for it, linux automatically detected it, and I was able to mount it from /dev/sda1straight away. Now, for the backup itself, this is stupidly simple, and for simple home use - absolutely perfect for me.

I simply setup a cronjob that copies from my local photo directory, to my USB drive, it's a one-liner which does the following things:

  • Copies recursively
  • Preserves timestamps and ownership permissions
  • Backs up "incrementally" - i.e. it doesn't copy your whole directory each time, only files that are changed.
  • Preserves links

cp -au /path/to/photos/ /mnt/backup/

I simply saved this file in the cron.daily folder, and gave it the permissions 755. Now I feel a bit safer with an extra copy. If your drive is permanently attached to your computer, don't forget to add an entry into /etc/fstab so it mounts each bootup!


watermark an image in php

Tuesday 15th January 2008 23:03

Occasionally when uploading your own photos, or artwork, or even if you run a site that hosts images and you wish to mark them, watermarking can be a useful technique. The aim is to simply overlay an unobtrusive graphic over your source image, I find white text, with a black shadow seems to work the best on both light and dark source images.

It's rather easy in PHP and GD2, and as a bonus we can use a PNG image with alpha transparancy as the "watermark" image, which means proper antialiasing on text, and dropshadows are possible!

You'll need a source JPG image, and also a small watermark image - the script below is well commented so you can see how each step works, simply change the first two variables to point to your image files on the server.

An example using my setup below can be found here (water mark is in the bottom right corner).

/*
/* setup the source file and watermark */
    
$sourceImg    'beach_large.jpg';
$watermarkImg 'watermark.png';
    
/*
/* create source file with alphablending */
            
$image imagecreatefromjpeg($sourceImg);
imagealphablending($imagetrue); 

/*
/* create watermark holder */
    
$watermark imagecreatefrompng($watermarkImg);
            
/*
/* get image and watermark dimensions */
            
$width      imagesx($image);
$height     imagesy($image);

$wmWidth    imagesx($watermark);
$wmHeight   imagesy($watermark);

/*
/* caclulate where to place watermark */
            
$xPos $width $wmWidth;
$yPos $height $wmHeight;
            
/*
/* Copy the watermark to the top right of original image */

imagecopy($image$watermark$xPos$yPos00$wmWidth$wmHeight); 
            
/*
/* output image directly to browser */
            
header("Content-Type: image/jpeg");
imagejpeg($image);


photw: city train station

Sunday 13th January 2008 23:04

Major interchange just near North Terrace.


View this photo on the map »

photw: busy beach

Tuesday 8th January 2008 23:18

Popular day down at the beach:


View this photo on the map »

photw: jetty sunset

Monday 31st December 2007 01:08

A very hot night looking over a jetty


View this photo on the map »

Next Page »




netforge logo
netforge provides high quality and friendly website design services to business. We're Australian based and reliable... (find out more).