1. Toby Davies
  2. backup-plan

Commits

None  committed e208b20

[svn r28] Changed to logical tests rather than ==0 tests in backup-plan syntax to simplify

  • Participants
  • Parent commits e1ac947
  • Branches trunk

Comments (0)

Files changed (3)

File backup-controller.sh

View file
  • Ignore whitespace
 	if [ "$DECRYPT" ] ; then 
 	    file="${file/%.enc}.enc"
 	fi
-#	log="${file/.tar.gz/.log}" 
 
 	from_file="${file/#/$from:}"
 	to_file="${file/#/$to:}"
 	else
 	    touch "$local_file"
 	fi
-	
 	rsync "$from_file" "$local_file"
 	local_file="$(decrypt "$local_file")"
 	file="${local_file/#$LOCAL_CACHE/$BAKDIR}"
 	to_file="${file/#/$to:}"
-	
+	set +x
 	if [ "$ENCRYPT" ] ; then
 	    local_file="$(encrypt "$local_file")"
 	    file="${local_file/#$LOCAL_CACHE/$BAKDIR}"
     base="$1"
     shift
     for e in "$@" ; do
-	if (( $(date -d "$base" "+$e") == 0 )) ; then
+	if (( $(date -d "$base" "+$e") )) ; then
 	    return 0
 	fi
     done
 	eval 'echo "${'"$WHAT"'['"$KEY"']}"'
 	;;
     available-backups)
-	for drive in "${ALL_DRIVES[@]}"; do
+	for drive in "${ALL_DRIVES[@]}" "${OTHER_BAKDIRS[@]}"; do
 	    if (isMounted "$drive") ; then
 		for h in "${HOSTS[@]}" ; do
 		    availableBackups "$h" ":$drive" | sed 's|^|'"$h:"'|'

File example.bplan

View file
  • Ignore whitespace
 
 #in $full and $diff %d,%w,%m are replaced with the day of the month, day of the week (sunday=0) and month of the year respectively
 #(you can use anything accepted as a format in date which means '%'s have to be escaped as %%)
-#if any of the mathematical expression equals 0 then the backup is executed
+#if any of the logical expressions is true then the backup is executed
 #a full backup overides a diff backup (if both should occur, only the full will)
-diff=("%w-1" "%w-2" "%w-4" "%w-5")
 
-full=("%w-3")
+diff=("%w > 1")
+
+full=("%w==3")
 
 #where to store the tarballs (local machine [controller] is implicit)
 stores=("isenguard2")
 
 #given a date $1, what _external_ media should we try to mount
 drives() {
-    echo "${Drive:-/media/$(date -d "$1" "+%A" | tr '[[:upper:]]' '[[:lower:]]' )}"
+    echo "${Drive:-/media/$(date -d "$1 -1 day" "+%A" | tr '[[:upper:]]' '[[:lower:]]' )}"
 }
 
 ALL_DRIVES=( /media/monday /media/tuesday /media/wednesday /media/thursday /media/friday )

File recovery.php

View file
  • Ignore whitespace
 <?php
+
 function e($s){
   return escapeshellarg("$s")?:"''";
-  }
+}
 function cmd(){
   $args=func_get_args();
   $fmt=array_shift($args);
   $cmd=vsprintf($fmt,array_map('e',$args));
-
-  //echo "$cmd\n";
-
+  
+  echo "$cmd\n";
+  
   $result=trim(shell_exec($cmd));
   
   if($result != "")
   return array();
 }
 
-function getPlans()
-{
+function getPlans(){
   return glob("./*plan");
 }
 
-function getBackups($plan)
-{
+function getBackups($plan){
   return cmd('./backup-controller plan %1$s available-backups', $plan);
 }
 
-function getFiles($plan, $host, $store, $date, $drive, $within="/")
-{
+function getFiles($plan, $host, $store, $date, $drive, $within="/"){
   $files=cmd('./backup-controller -s %s -b %s -t %s -x %s browse %s 2>/dev/null',$host,$store,$date,$drive,$within);
   $r=empty($files)?null:$files;
   return $r;
 }
 
-function restoreFiles($plan,$host,$store,$date,$drive,$path,$restoreTo=null)
-{
+function restoreFiles($plan,$host,$store,$date,$drive,$path,$restoreTo=null){
   $restoreTo=$restoreTo?:"$host:/";
   $rdate='.bkp-'.date("Y-m-d_H:i:s");
   $cmd="./backup-controller -s $host:$path -b $store -t $date -x $drive-r $host:/ -v $rdate restore 2>&1";
   return cmd('./backup-controller -s %s:%s -b %s -t %s -x %s -r %s -v %s restore 2>&1', $host,$path,$store,$date,$drive,$restoreTo,$rdate);
 }
 
-function downloadRestored($plan,$host,$store,$date,$drive,$path)
-{
+function downloadRestored($plan,$host,$store,$date,$drive,$path){
   header("Content-type: application/zip");
   header("Content-Disposition: attachment\; filename=".basename($path).".zip");
   passthru("./backup-controller -z -s ".e($host)." -b ".e($store)." -x ".e($drive)." -t ".e($date)." part-tarball ".e($path)." 2>/dev/null");
   die();
 }
 
+function drivesOnDate($plan,$date){
+  todo();
+}
+
 $step = isset($_GET['step'])?$_GET['step']:'plan';
-$actionAppliesRegex="/./";
+$actionAppliesRegex="/.*/";
 $otherActions=array();
 $nextStep=null;
 $preamble="Select one of the options below";
    $options=getBackups($plan);
    $preamble= "FileHost : BackupHost : Date : Drive/Folder";
    break;
-  case 'browse':
+ case 'browse':
    $nextStep='browse';
    $options=getFiles($plan,$host,$store,$date,$dir,$path);
    $otherActions=array('restore','download .zip');
    //data has already been sent, no need for UI so die()
    die();
    break;
-
  case 'restore':
    $options=array("");
    $otherActions=array('back','confirm restore');
    $options=restoreFiles($plan,$host,$store,$date,$dir,$path);
    $actionAppliesRegex='/^$/';
    break;
+ case 'drives':
+   $options=drivesOnDate($plan,$_GET['date']);
+   $actionAppliesRegex='/^$/';
+   break;
 }
 
+
+// UI starts here 
+
 echo "<h2>".ucwords($step)."</h2>
 <p>$preamble</p>
 <ul>\n";