[slbackup-commit] CVS update: slbackup-php/src index.php

finnarne-guest at alioth.debian.org finnarne-guest at alioth.debian.org
Tue Apr 17 00:30:26 UTC 2007


  User: finnarne-guest
  Date: 07/04/17 00:30:26

  Modified:    src      index.php
  Log:
  Now It's almost possible to fetch a file from the backup
  
  Revision  Changes    Path
  1.21      +40 -7     slbackup-php/src/index.php
  
  Index: index.php
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup-php/src/index.php,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- index.php	17 Apr 2007 00:13:24 -0000	1.20
  +++ index.php	17 Apr 2007 00:30:26 -0000	1.21
  @@ -20,6 +20,32 @@
   
   
   
  +function fetchfile ($passwd, $clientdir, $location, $file) {
  +global $backuphost, $backupuser, $ssh_options, $ssh_askpass ;
  +
  +    $out= "" ; 
  +    $cmd = sprintf ("ssh %s %s@%s 'cat %s%s/%s'", 
  +   		     $ssh_options, $backupuser, 
  +		     $backuphost, $clientdir, $location, $file ) ; 
  +
  +    $desc[0] = array ("pipe", "r") ; 
  +    $desc[1] = array ("pipe", "w") ; 
  +    $desc[2] = array ("file", "/tmp/error.log", "a") ; 
  +
  +    $env = array ('SSH_ASKPASS' => $ssh_askpass, 
  +		  'DISPLAY' => ':nowhere') ; 
  +    $proc = proc_open ($cmd, $desc, $pipes, '/tmp', $env) ; 
  +    if (is_resource ($proc)) {
  +	fprintf ($pipes[0], "%s\n", $passwd) ; 
  +	fclose ($pipes[0]) ; 
  +	while ($line = fgets ($pipes[1], 1024))
  +	    $out .= $line ; 
  +	fclose ($pipes[1]) ; 
  +	proc_close ($proc) ; 
  +    }
  +    return $out ; 
  +}
  +
   function listloc ($passwd, $clientdir, $location, $sub = "") {
   global $backuphost, $backupuser, $ssh_options, $ssh_askpass ;
   
  @@ -36,10 +62,6 @@
      		     $ssh_options, $backupuser, 
   		     $backuphost, $clientdir, $location, $sub ) ; 
   
  -    $cmd = sprintf ("ssh %s %s@%s 'find %s%s/%s -maxdepth 1 -mindepth 1 -type d'", 
  -   		     $ssh_options, $backupuser, 
  -		     $backuphost, $clientdir, $location, $sub ) ; 
  -
       $desc[0] = array ("pipe", "r") ; 
       $desc[1] = array ("pipe", "w") ; 
       $desc[2] = array ("file", "/tmp/error.log", "a") ; 
  @@ -59,9 +81,10 @@
   	fclose ($pipes[1]) ; 
   	proc_close ($proc) ; 
       }
  -    $cmd = sprintf ("ssh %s %s@%s find %s/%s/%s -maxdepth 1 -mindepth 1 -type f ", 
  +    $cmd = sprintf ("ssh %s %s@%s 'find %s%s/%s -maxdepth 1 -mindepth 1 -type f'", 
      		     $ssh_options, $backupuser, 
  -		     $backuphost, $clientdir, $location, $sub) ; 
  +		     $backuphost, $clientdir, $location, $sub ) ; 
  +
       $proc = proc_open ($cmd, $desc, $pipes, '/tmp', $env) ; 
       if (is_resource ($proc)) {
   	fprintf ($pipes[0], "%s\n", $passwd) ; 
  @@ -69,7 +92,8 @@
   	while ($line = fgets ($pipes[1], 1024))
   	    $loc[] = array ('type' => 'file', 
   	                    'name' => basename (trim($line)), 
  -	                    'sub' => trim ($line)) ; 
  +	                    'sub' => substr (trim ($line), strlen ($clientdir) + strlen ($location) + 1)) ; 
  +
   	fclose ($pipes[1]) ; 
   	proc_close ($proc) ; 
       }
  @@ -325,6 +349,7 @@
           case "restore":
           case "restoreclient":
           case "restorelocation":
  +        case "restorefile":
           case "logout":
               $submit=$key ; 
               break ;
  @@ -480,6 +505,14 @@
   	$config["clients"][$client]["location"][] = $newconf["newloc"] ; 
   	writeconf ($passwd, $config) ; 
   	break ;
  +    case "restorefile": 
  +        if (empty($client) || empty ($newconf["location"]))
  +            break ; 
  +         debug (fetchfile ($passwd, 
  +			   sprintf ("%s/%s", $config["server_destdir"], $client), 
  +			   $newconf["location"], $newconf["file"])) ; 
  +
  +	break ; 
       case "restorelocation": 
           if (empty($client) || empty ($newconf["location"]))
               break ; 
  
  
  



More information about the slbackup-commit mailing list