echo "This command will init the data for $changer_name\n";
- if(file_exists("$BASE_DATA/$changer_name.db")) {
+ if(file_exists("$BASE_DATA/$changer_name.db")&&check_init($changer_name)) {
//echo "Daemon is already init'd, are you sure you wish to do this, it will loose all config [y/n]:";
$r = readline("Daemon is already init'd, are you sure you wish to do this, it will loose all config [y/n]:");
if($r == "y") {
if($rb == "") $rb = 1;
if($rc == "") $rc = 20;
- db_getDB($changer_name);
+ conf_setVal($changer_name, "automountdir", "$ra");
+ conf_setVal($changer_name, "ndrives", "$rb");
+ conf_setVal($changer_name, "tapesize", "$rc");
+
+ // check if they were set
+ echo "got: ".conf_getVal($changer_name, "automountdir").", and ".conf_getVal($changer_name, "tapesize").", and ".conf_getVal($changer_name, "ndrives")."\n";
+}
+
+function check_init_and_fail($changer)
+{
+ $lk = conf_getVal($changer, "automountdir");
+ if(!$lk) {
+ echo "DB not init'd yet, please run init first\n";
+ exit(0);
+ }
+}
+
+function check_init($changer)
+{
+ $lk = conf_getVal($changer, "automountdir");
+ if(!$lk) {
+ return false;
+ }
+
+ return true;
}
function add_disk()
// creating pbdc/changer_name/stuff.
global $BASE_DATA, $BASE_LIB, $BACULA_USER, $argv;
+ check_init_and_fail($argv[1]);
+
$dh = opendir("/dev/disk/by-uuid");
$disk = "";
// now we try and init the disk
// we have to get automount directory config
- //$k = mkdir();
+ $dir = conf_getVal($argv[1], "automountdir");
+ if(!is_dir($dir)) {
+ echo "cant find automount directory, $dir\n";
+ }
+ $mkd = "$dir/".basename($disk[$i]["syml"])."/pbdc/".$argv[1]."/tapes/";
+ $k = mkdir($mkd, 0700, true);
+
+ if(!is_dir($mkd)) {
+ echo "Error, couldn't create directory, check permissions on $mkd?\n";
+ }
+
+ $ts = conf_getVal($argv[1], "tapesize");
+ $max = (int)($disk[$i]["size"]/$ts);
+
+ $k = (int)(readline("No of tapes to create [max:$max] @ ".$ts."gb each:"));
+ if($k > $max) {
+ echo "Sorry, max number of tapes is $max, creating $max instead\n";
+ }
+
+ $did = add_diskToDB($argv[1], basename($disk[$i]["syml"]));
+
+ if(!$did) {
+ echo "Disk already exists, doing nothing\n";
+ exit(0);
+ }
+
+ //echo "did: $did\n";
}
?>
\ No newline at end of file
global $BASE_DATA, $BASE_LIB, $BACULA_USER;
try {
- $dbobject = new PDO("sqlite:$BASE_DATA/$changer_name"."db");
+ $dbobject = new PDO("sqlite:$BASE_DATA/$changer_name".".db");
} catch(PDOException $exep) {
echo "<font color='red'>Cannot open sqlitedb, ".$exep->getMessage()."</font><br>";
return;
}
}
-function conf_getVal($name)
+function conf_getVal($changer, $name)
{
- $db = db_getDB();
+ $db = db_getDB($changer);
- $sql = "select conf_val from conf where conf_name=='$name'";
- error_log("from getval: ".$sql);
+ $sql = "select config_value from config where config_name=='$name'";
+ //error_log("from getval: ".$sql);
$res = $db->query($sql);
$val = false;
foreach($res as $row) {
- $val = $row["conf_val"];
+ $val = $row["config_value"];
}
return $val;
}
-function conf_setVal($name, $value)
+function conf_setVal($changer, $name, $value)
{
- $db = db_getDB();
+ $db = db_getDB($changer);
- $sql = "delete from conf where conf_name=='$name'";
+ $sql = "delete from config where config_name=='$name'";
$db->query($sql);
- $sql = "insert into conf values ('$name', '$value')";
+ $sql = "insert into config values ('$name', '$value')";
$db->query($sql);
- error_log("from setval: ".$sql);
+ //error_log("from setval: ".$sql);
+}
+
+function add_diskToDB($changer, $diskid)
+{
+ $db = db_getDB($changer);
+
+ $sql = "select * from disk_list where disk_name=='$diskid'";
+ $res = $db->query($sql);
+ if(!$res) return false;
+
+ $val = false;
+ foreach($res as $row) {
+ $val = $row["disk_id"];
+ }
+
+ if(!$val) {
+ $sql = "insert into disk_list values(NULL, '$diskid')";
+ $db->query($sql);
+ return $db->lastInsertId();
+ } else {
+ echo "Disk already existed in db, will create more tapes?\n";
+ }
+
+ return $val;
}
?>
\ No newline at end of file