|
From: Joe Z. <jz...@co...> - 2004-03-26 03:57:44
|
Rene Rask wrote:
>Hi
>
>The last email about db3/db4 support finally got to me. So I put a patch
>together that checks for db3 and db4.
>
>Please sanity check this as I haven't even tried to run this. If it
>works and there are no arguments against it, I'll commit it to cvs. With
>this we should make a bugfix release.
>
>Joe, I'm sorry if this is crossing into your current work. If you have
>something better coming, please consider this a temporary solution.
>
>Applies with:
>cd your.bobs.cvs.dir
>patch -p1 < dba.patch
>
>Cheers
>Rene
>
>
I'll try this patch at work where I've recently started using bobs to
backup file servers to a single large drive. And it's been working
great! I haven't done any coding for this patch yet, just some notes, so
you're not stepping on my toes at all. I do think the code for the db
check should be done as a separate function with the result returned to
the functions that do db operations. That way if we add other databases
we only need to change the code in one place. I'll try it out and let
you know.
I made some changes to start cmdloop as a service from /etc/init.d
instead of crontab, and to log the output of cmdloop to
/var/log/bobs.log. I need to review my code and run it by everyone
before checking it in.
Thanks,
Joe
>
>
>------------------------------------------------------------------------
>
>diff -ur bobs/inc/class_db.php bobs_dba/inc/class_db.php
>--- bobs/inc/class_db.php 2002-09-29 08:08:01.000000000 +0200
>+++ bobs_dba/inc/class_db.php 2004-03-25 18:21:27.308604742 +0100
>@@ -18,6 +18,7 @@
>
> var $db = ''; // holds an array of database pointers
> var $db_access = ''; // holds information about which type of db connection is open
>+ var $db_type = ''; // the type of dba we use
> var $key = '';
> var $value = '';
> var $db_is_last_key = FALSE; // if this is TRUE then $this->key is the last in the db
>@@ -25,7 +26,6 @@
>
> var $time; // this is a variable to hold information about performance
>
>-
> function database ($config) {
>
> // class constructor
>@@ -40,6 +40,22 @@
> $this->session_id = $config["session_id"];
> $this->filelinks = $config["filelinks"];
>
>+ // check what dba type we should use
>+ $tmpfile = tempnam("/tmp", "BOBS");
>+ $dbcheck = @dba_open($tmpfile, "c", "db3");
>+ if ( $dbcheck === FALSE ) {
>+ $dbcheck = @dba_open($tmpfile, "c", "db4");
>+ if ( $dbcheck === FALSE ) {
>+ echo "Could not create a database of type db3 or db4 (tried both)\n";
>+ } else {
>+ dba_close($dbcheck);
>+ $this->db_type = "db4";
>+ }
>+ } else {
>+ dba_close($dbcheck);
>+ $this->db_type = "db3";
>+ }
>+
> return;
> }
>
>@@ -58,12 +74,12 @@
> if ( !isset($this->db[$where][$type]) ) {
> if ( file_exists ($db) ) {
> if ( is_writeable($db) ) {
>- $this->db[$where][$type] = dba_open($db, "w", "db3");
>+ $this->db[$where][$type] = dba_open($db, "w", $this->db_type);
> } else {
>- $this->db[$where][$type] = dba_open($db, "r", "db3");
>+ $this->db[$where][$type] = dba_open($db, "r", $this->db_type);
> }
> } else {
>- $this->db[$where][$type] = dba_open($db, "c", "db3");
>+ $this->db[$where][$type] = dba_open($db, "c", $this->db_type);
> }
> }
> return;
>@@ -167,7 +183,7 @@
> // this function will clear a database.
>
> $db = $this->db_location($where, $type);
>- $this->db[$where][$type] = dba_open($db, "n", "db3");
>+ $this->db[$where][$type] = dba_open($db, "n", $this->db_type);
> return;
> }
>
>diff -ur bobs/inc/templates/backup_create_databases.php bobs_dba/inc/templates/backup_create_databases.php
>--- bobs/inc/templates/backup_create_databases.php 2004-03-15 13:53:34.000000000 +0100
>+++ bobs_dba/inc/templates/backup_create_databases.php 2004-03-25 18:21:43.534218913 +0100
>@@ -9,9 +9,18 @@
> var $id = ''; // database handle
>
> function create ( $db ) {
>+
>+ // check what dba type we should use
> $this->id = dba_open ($db, "n", "db3");
>+ if ( $this->id === FALSE ) {
>+ $this->id = dba_open ($db, "n", "db4");
>+ if ( $this->id === FALSE ) {
>+ echo "Could not create a database of type db3 or db4 (tried both)\n";
>+ }
>+ }
> return;
> }
>+
> function closedb () {
> dba_sync($this->id);
> dba_close ($this->id);
>@@ -96,14 +105,20 @@
> // open the file index db
> $id = dba_open($db, "r", "db3");
> if (!$id) {
>- echo "dba_open failed\n";
>- exit;
>+ $id = dba_open($db, "r", "db4");
>+ if (!$id) {
>+ echo "dba_open failed\n";
>+ exit;
>+ }
> }
> // create a new dir database.
> $dir_id = dba_open ('{DIR_DB}', "n", "db3");
> if (!$dir_id) {
>- echo "dba_open failed\n";
>- exit;
>+ $dir_id = dba_open ('{DIR_DB}', "n", "db4");
>+ if (!$dir_id) {
>+ echo "dba_open failed\n";
>+ exit;
>+ }
> }
>
> // set the first key
>diff -ur bobs/systemcheck.php bobs_dba/systemcheck.php
>--- bobs/systemcheck.php 2004-01-20 05:14:47.000000000 +0100
>+++ bobs_dba/systemcheck.php 2004-03-25 18:21:13.762596560 +0100
>@@ -292,20 +292,24 @@
> putfail();
> }
>
>-$t->assign ('ITEM', "Checking for db3 database support");
>+$t->assign ('ITEM', "Checking for dba (db3 or db4) database support");
> $tempfile = '/tmp/bobstest' . posix_getpid();
>-$handle = dba_open("$tempfile", "c", "db3"); // open a temporary database
>+$handle = @dba_open("$tempfile", "c", "db3"); // open a temporary database
>+if (!$handle) {
>+ $handle = @dba_open("$tempfile", "c", "db4"); // open a temporary database
>+ if (!$handle) {
>+ $t->assign ('STATUS', 'FAIL');
>+ $t->assign ('HELP', "dba database support is not working.<br>
>+ You need to check your php configuration and<br>
>+ include dba database support.");
>+ putfail();
>+ }
>+}
> if ($handle) {
> dba_close($handle); // close it
> unlink($tempfile); // and delete it.
> $t->assign ('STATUS', 'PASS');
> putpass();
>-} else {
>- $t->assign ('STATUS', 'FAIL');
>- $t->assign ('HELP', "db3 database support is not working.<br>
>- You need to check your php configuration and<br>
>- include db3 database support.");
>- putfail();
> }
>
> // ----------------------------
>
>
|