[slbackup-commit] CVS update: slbackup-php/src index.php
finnarne-guest at alioth.debian.org
finnarne-guest at alioth.debian.org
Tue Apr 17 09:24:37 UTC 2007
User: finnarne-guest
Date: 07/04/17 09:24:37
Modified: src index.php
Log:
added maintenance (cleanup) of old backups
Revision Changes Path
1.26 +76 -0 slbackup-php/src/index.php
Index: index.php
===================================================================
RCS file: /cvsroot/slbackup/slbackup-php/src/index.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- index.php 17 Apr 2007 06:15:26 -0000 1.25
+++ index.php 17 Apr 2007 09:24:37 -0000 1.26
@@ -19,6 +19,60 @@
*/
+function removesnapshots ($passwd, $clientdir, $snapshot) {
+global $backuphost, $backupuser, $ssh_options, $ssh_askpass ;
+
+ $cmd = sprintf ("ssh %s %s@%s 'rdiff-backup --force --remove-older-than %s %s'",
+ $ssh_options, $backupuser,
+ $backuphost, $snapshot, $clientdir) ;
+
+ $snapshots = array () ;
+ $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)) {
+ $snapshots[] = $line ;
+ }
+ fclose ($pipes[1]) ;
+ proc_close ($proc) ;
+ }
+ return $snapshots ;
+}
+
+function listsnapshots ($passwd, $clientdir) {
+global $backuphost, $backupuser, $ssh_options, $ssh_askpass ;
+
+ $cmd = sprintf ("ssh %s %s@%s 'find %s/rdiff-backup-data -maxdepth 1 -name \"increments.*\" -printf %s'",
+ $ssh_options, $backupuser,
+ $backuphost, $clientdir, '"%P\n"') ;
+
+ $snapshots = array () ;
+ $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)) {
+ $snapshots[] = substr ($line, 11, 25) ;
+ }
+ fclose ($pipes[1]) ;
+ proc_close ($proc) ;
+ }
+ return $snapshots ;
+}
+
function fetchfile ($passwd, $clientdir, $location, $file) {
global $backuphost, $backupuser, $ssh_options, $ssh_askpass ;
@@ -350,9 +404,16 @@
case "restoreclient":
case "restorelocation":
case "restorefile":
+ case "maint":
+ case "removesnapshot":
case "logout":
$submit=$key ;
break ;
+ case "selected":
+ $selected=$value ;
+ case "snapshot":
+ $snapshot=$value ;
+ break ;
case "client":
$client=htmlspecialchars(trim($value)) ;
break ;
@@ -530,6 +591,14 @@
$newconf["location"], $newconf["sub"]) ;
break ;
+ case "removesnapshot":
+ if (!empty ($snapshot) and ($selected == $client))
+ $smarty->assign ('removed', removesnapshots ($passwd, sprintf ("%s/%s", $config["server_destdir"], $client), $snapshot)) ;
+ case "maint":
+ if (!empty($client)) {
+ $smarty->assign ('snapshots', listsnapshots ($passwd, sprintf ("%s/%s", $config["server_destdir"], $client))) ;
+ }
+ break ;
default:
$log = array ('start' => '', 'end' => '') ;
foreach ($config["clients"] as $key => $value)
@@ -553,6 +622,13 @@
$smarty->assign ('locations', $config["clients"][$client]["location"]) ;
$smarty->display ('restore.tpl') ;
break ;
+ case "removesnapshot":
+ case "maint":
+ $clients = array_keys($config["clients"]) ;
+ $smarty->assign ('clients', $clients) ;
+ $smarty->assign ('client', $client) ;
+ $smarty->display ('maint.tpl') ;
+ break ;
case "config":
case "addclient":
case "server":
More information about the slbackup-commit
mailing list