no idea.
authorpaulr <me@pjr.cc>
Sun, 11 Jul 2010 13:59:48 +0000 (23:59 +1000)
committerpaulr <me@pjr.cc>
Sun, 11 Jul 2010 13:59:48 +0000 (23:59 +1000)
bin/pbdc-bacula.php

index c29e8d7..ac2ebcc 100644 (file)
@@ -49,11 +49,53 @@ function unload_tape()
 {
        global $BASE_DATA, $BASE_LIB, $BACULA_USER, $changer, $argv;
        
+       $tapeloc = conf_getVal($changer, "drivelocation");
+       $changer = $argv[1];
+       $taped = $argv[5];
+       
+       unlink("$tapeloc/$changer-drive$taped");
 }
 
 function load_tape()
 {
        global $BASE_DATA, $BASE_LIB, $BACULA_USER, $changer, $argv;
+               
+       $changer = $argv[1];
+       $taped = $argv[5];
+
+       $db = db_getDB($argv[1]);
+       
+       $res = $db->query("select * from disk_list order by disk_id");
+       
+       $tapeloc = conf_getVal($changer, "drivelocation");
+       $amloc = conf_getVal($changer, "automountdir");
+       
+       $ret = false;
+       $slot = $argv[3];
+
+       $i=1;
+       foreach($res as $row) {
+               //echo "Listing tapes for disk ".$row["disk_id"].", ".$row["disk_name"]."\n";
+               //echo "dir: $amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/\n";
+               //exit(0);
+               $dh = opendir("$amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/");
+               while(($file = readdir($dh)) !== false) {
+                       if(ereg("d[0-9]+_vol[0-9]+", $file)!=false) {
+                               if($i == $slot) {
+                                       unlink("$tapeloc/$changer-drive$taped");
+                                       symlink("$amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/$file", "$tapeloc/$changer-drive$taped");
+                                       exit(0);
+                               }
+                               $i++;
+                       } else {
+                               //echo "didnt match: $file\n";
+                       }
+                       //exit(0);
+               }
+               closedir($dh);
+       }
+       
+       echo "0\n";
        
 }
 
@@ -61,17 +103,114 @@ function loaded_tape()
 {
        global $BASE_DATA, $BASE_LIB, $BACULA_USER, $changer, $argv;
        
+       $changer = $argv[1];
+       $taped = $argv[5];
+
+       $db = db_getDB($argv[1]);
+       
+       $res = $db->query("select * from disk_list order by disk_id");
+       
+       $tapeloc = conf_getVal($changer, "drivelocation");
+       $amloc = conf_getVal($changer, "automountdir");
+       
+       $rl = "";
+       if(file_exists("$tapeloc/$changer-drive$taped")) {
+               $rl = basename(readlink("$tapeloc/$changer-drive$taped"));
+       } else {
+               echo "0\n";
+               exit(0);
+       }
+       
+       $ret = false;
+       $i=1;
+       foreach($res as $row) {
+               //echo "Listing tapes for disk ".$row["disk_id"].", ".$row["disk_name"]."\n";
+               //echo "dir: $amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/\n";
+               //exit(0);
+               $dh = opendir("$amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/");
+               while(($file = readdir($dh)) !== false) {
+                       if(ereg("d[0-9]+_vol[0-9]+", $file)!=false) {
+                               if($rl == $file) {
+                                       echo "$i\n";
+                                       exit(0);
+                               }
+                               $i++;
+                       } else {
+                               //echo "didnt match: $file\n";
+                       }
+                       //exit(0);
+               }
+               closedir($dh);
+       }
+       
+       echo "0\n";
 }
 
 function list_tapes()
 {
        global $BASE_DATA, $BASE_LIB, $BACULA_USER, $changer, $argv;
        
+       $changer = $argv[1];
+
+       $db = db_getDB($argv[1]);
+       
+       $res = $db->query("select * from disk_list order by disk_id");
+       
+       $amloc = conf_getVal($changer, "automountdir");
+       
+       $ret = false;
+       $i=1;
+       foreach($res as $row) {
+               //echo "Listing tapes for disk ".$row["disk_id"].", ".$row["disk_name"]."\n";
+               //echo "dir: $amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/\n";
+               //exit(0);
+               $dh = opendir("$amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/");
+               while(($file = readdir($dh)) !== false) {
+                       if(ereg("d[0-9]+_vol[0-9]+", $file)!=false) {
+                               echo "slot $i: $file\n";
+                               $i++;
+                       } else {
+                               //echo "didnt match: $file\n";
+                       }
+                       //exit(0);
+               }
+               closedir($dh);
+       }
+       
 }
 
 function num_slots()
 {
        global $BASE_DATA, $BASE_LIB, $BACULA_USER, $changer, $argv;
+
+       $changer = $argv[1];
+
+       $db = db_getDB($argv[1]);
+       
+       $res = $db->query("select * from disk_list order by disk_id");
+       
+       $amloc = conf_getVal($changer, "automountdir");
+       
+       $ret = false;
+       $i=1;
+       foreach($res as $row) {
+               //echo "Listing tapes for disk ".$row["disk_id"].", ".$row["disk_name"]."\n";
+               //echo "dir: $amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/\n";
+               //exit(0);
+               $dh = opendir("$amloc/".$row["disk_name"]."/pbdc/".$argv[1]."/tapes/");
+               while(($file = readdir($dh)) !== false) {
+                       if(ereg("d[0-9]+_vol[0-9]+", $file)!=false) {
+                               $i++;
+                       } else {
+                               //echo "didnt match: $file\n";
+                       }
+                       //exit(0);
+               }
+               closedir($dh);
+       }
+       $i--;
+       
+       echo "$i\n";
        
 }