bloginfo('name');

bloginfo('description');

Archives Posts

Backup remotely via Perl

Mai 29th, 2007 by Blu:RayNe

Ok, i guess you love that cheap servers only with FTP and HTTP, and minimal PHP4-Timeout and lame CGI and no real possibility but to do a good backup job. Well, Perl was once a dominant language and can do much for you.

The benefits of following backup solutions are as follows:

  • Backup is done via calling an URL
  • that invokes the mysqldump utility to backup your database to a local director, that is preferable outside the webroot
  • the data is then gzipped
  • old backups are automatically deleted
  • and then backed up via FTP to another server
  • and while a second server gets the backup it is more secure than having all on a single server

Put this in you cgi-bin folder and remotely call it via CURL or test it via the browser. Don’t forget tot set chmod 755 for the files! If you backup to a directory in the webroot don’t forget to protect that directory by e.g. setting a up an .htacess-file!

#!/usr/bin/perl -w

use CGI;
use POSIX qw(strftime);
use Time::Local;

$query    = new CGI();
$file     = $query->param(‘file’);
$filename = $query->param(‘filename’);

print "Content-Type: text/plain\n\n";
# print "Content-type: application/octet-stream\n";
# print "Content-Disposition: attachment; filename=".$filename."\n";
# print "Pragma: no-cache\n";
# print "bash ".$file;

sub backupMysql
{
    my ($host)     = $_[0];
    my ($username) = $_[1];
    my ($password) = $_[2];
    my ($database) = $_[3];
    my ($title) = $_[4];

    $time = time;
    $filename = $title."-".$database."-".strftime("%Y%m%d-%H%S", localtime($time));
    print "Backup of \"".$title."\" (".$database.")…";
    system "mysqldump -e –add-drop-table –add-locks –allow-keywords -h".$host." -u".$username." -p".$password." ".$database." > ../../backup/".$filename.".sql";
    # print "GZip ".$filename."…\n";
    system "gzip ../../backup/".$filename.".sql";
    # print "Unlink ".$filename.".sql…\n";
    unlink "../../backup/".$filename.".sql";
    print "done.\n";
}

# Delete previous backups
if (-d "../backup/") {
    $where = "../backup/";
    while (defined($next = <$where/*.sql.gz>)) {
        unlink($next);
    }
}

backupMysql("<em>host</em>", "<em>username</em>", "<em>password</em>", "<em>database</em>", "<em>mybackupname</em>");

 

Optional .htaccess-File:

<Files ~ ".*(sql|gz|tar)">
    Deny from all
</Files>
 

Then call the URL by cronjob:

#!/bin/sh

remoteAddress="<em>ftp://user@yourftp.com</em> -p <em>password</em>"
localAddress="<em>/home/Backup/mybackupname</em>"

timeThreshold=15
mirrordirOptions="-v –keep-files  –no-chown –no-chmod  –num-backups 30 –mtime-threshold $timeThreshold "

echo "Backup to $localAddress — `date +"%a, %C.%B %Y"`"
echo -n "[`date +%H:%M:%S`] Killing runnung instances of mirrordir…"

/usr/bin/killall -9 mirrordir &amp;2>1 > /dev/null
echo "done."

mkdir -p $localAddress/htdocs > /dev/null

echo  "[`date +%H:%M:%S`] Backup of relevant databases…"
curl http://www.yourdomain.com/cgi-bin/backup/mysql.cgi
echo "done."

echo -n "[`date +%H:%M:%S`] Backup of remote FTP…"
/usr/bin/mirrordir $mirrordirOptions $remoteAddress $localAddress/htdocs
echo "done."

echo "[`date +%H:%M:%S`] Finished."
 

If you don’t have mirrordir or curl install it via aptitude install mirrordir curl on your debian box.

Filed under Allgemein, Datenbanken, Linux having No Comments »

Archives Posts

CouchDB - Machen Sie sich es erst einmal gemütlich!

März 22nd, 2007 by Blu:RayNe

CouchDB bietet eine RESTful Datenbank, die über HTTP angesprochen werden kann. D.h. man erhält mit Anfragen wie GET, PUT, POST und DELETE eine einfache Möglichkeit eine Datenbank anzusprechen.

Herausragend ist hierbei natürlich die Einfachheit.

Zwar vermisse ich XPath- oder XQuery-ähnlich Anfragen, dafür bietet aber eine CouchDB eine SQL-like Syntax. Insgesamt kann gesagt werden, dass sich die Datenbank in Zukunft vielleicht zu einer erst zu nehmenden Alternative für LDAP herauskristallisiert.

Anwendungszwecke sehe ich als Authentifizierungs-Datenbank, wohl aber auch als Dokumenten-Management oder -Storage (inkl. Revision Control), sowie als generelle Ablage für Office-relevante Dinge wie E-Mails, Kontakte usw. (obwohl ja da CalDAV da auch schon ein netter Ansatz ist).

Eine Einführung in CouchDB in PHP gibt es hier.

Die Frage bleibt nur, warum wieder mal alles via HTTP zu funktionieren hat, inwieweit die Sicherheit berücksichtigt wurde, und inwiefern die Entwickler versuchen wollen die Performance zu steigern. Zu mindestens ein sehr interessantes Projekt.

Kommentar: Tja, und wann schafft man es endlich einen gemeinsamen OS-Standard für E-Mail, Kalender, Kontakte usw. zu schaffen? Ich will auf Mozilla Thunderbird, Lightning und CouchDB in Zukunft hoffen…

Filed under Allgemein, Datenbanken having 3 Comments »