From 86d3e89064d683b75ad6c236da5a037811ce6abb Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 11 Jul 2010 23:59:48 +1000 Subject: [PATCH] no idea. --- bin/pbdc-bacula.php | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 139 insertions(+), 0 deletions(-) diff --git a/bin/pbdc-bacula.php b/bin/pbdc-bacula.php index c29e8d7..ac2ebcc 100644 --- a/bin/pbdc-bacula.php +++ b/bin/pbdc-bacula.php @@ -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"; } -- 1.7.0.4