X-Git-Url: http://git.pjr.cc/?p=php-bacula-disk-changer.git;a=blobdiff_plain;f=bin%2Fpbdc.php;h=c1ea23d75fd1cf04802148e9945386465d9898d3;hp=b7b8d077136b46530fc43797a7327a739b478aa1;hb=10b3158464d931ccfa758eb648ca2e9b72aa0a86;hpb=45477c40560ea3bda92e4c03c7ed564228a92bd8 diff --git a/bin/pbdc.php b/bin/pbdc.php index b7b8d07..c1ea23d 100644 --- a/bin/pbdc.php +++ b/bin/pbdc.php @@ -52,7 +52,7 @@ function init() 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") { @@ -73,7 +73,31 @@ function init() 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() @@ -82,6 +106,8 @@ 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 = ""; @@ -123,6 +149,32 @@ function add_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