1#!/bin/csh 2# 3# $DragonFly: src/bin/cpdup/scripts/do_remote_host,v 1.2 2006/09/21 00:18:13 dillon Exp $ 4 5source params 6 7if ( "$argv" == "" ) then 8 echo "Specify host mounted in $backup_nfs (e.g. 'apollo'), and level." 9 echo "Level 0 - full backup, do not use hardlink trick" 10 echo "Level 1 - full backup, use hardlink trick but verify each file" 11 echo "Level 2 - full backup, use hardlink trick and stat shortcut" 12 echo "./do_remote_host <host> <level> > $remote_path/mirrors/<host>.log" 13 exit 1 14endif 15 16set host = "$argv[1]" 17set level = "$argv[2]" 18 19if ( ! -d $backup_nfs/$host ) then 20 echo "Host not found in $backup_nfs" 21 exit 1 22endif 23if ( ! -d $backup_path/mirrors/$host ) then 24 echo "No backup found for $host" 25 exit 1 26endif 27 28# Figure out the source directory 29# 30set source = `readlink $backup_path/mirrors/$host` 31if ( "$source" == "" ) then 32 echo "No backup found for $host at $backup_path/mirrors/$host" 33 echo "or it was not a softlink" 34 exit 1 35endif 36 37# Figure out the hardlink optimized side directory on 38# the target. 39# 40 41if ( $level != 0 ) then 42 set hlbase = `ssh $remote_host -n "readlink ${remote_path}/mirrors/$host"` 43 if ( "$hlbase" == "" ) then 44 echo "Missing softlink at ${remote_host}:${remote_path}/mirrors/${host}" 45 echo "cannot proceed. Perhaps you did not run a level 0 with" 46 echo "the do_remote script to create the hardlink base and softlink?" 47 exit 1 48 endif 49 50 if ( "$hlbase" == "$source" ) then 51 echo "SUCCEEDED - NO NEW BACKUP SINCE LAST TIME" 52 exit 0 53 endif 54endif 55 56# Figure out the target path and add prefixes 57# 58set basename = $source 59set target = ${remote_host}:${remote_path}/mirrors/${source} 60set source = $backup_path/mirrors/${source} 61set hlbase = ${remote_path}/mirrors/${hlbase} 62 63echo "---------- OFFSITE BACKUP OF $source ---------" 64echo "SOURCE $source" 65echo "HLBASE $hlbase" 66echo "TARGET $target" 67 68# Do the actual backup 69# 70 71set failed = 0 72 73switch($level) 74case 0: 75 echo "cpdup -i0 -s0 -I $source $target" 76 cpdup -i0 -s0 -I $source $target 77 if ( $status != 0 ) then 78 set failed = 1 79 endif 80 breaksw 81case 1: 82 echo "cpdup -f -i0 -s0 -I -H $hlbase $source $target" 83 cpdup -f -i0 -s0 -I -H $hlbase $source $target 84 if ( $status != 0 ) then 85 set failed = 1 86 endif 87 breaksw 88case 2: 89 echo "cpdup -i0 -s0 -I -H $hlbase $source $target" 90 cpdup -i0 -s0 -I -H $hlbase $source $target 91 if ( $status != 0 ) then 92 set failed = 1 93 endif 94 breaksw 95default: 96 echo "UNKNOWN BACKUP LEVEL, USE ONLY 0-2" 97 set failed = 1 98 breaksw 99endsw 100 101if ( $failed == 0 ) then 102 ssh $remote_host -n "rm -f ${remote_path}/mirrors/$host; ln -s $basename ${remote_path}/mirrors/$host" 103 sync 104 echo "SUCCEEDED" 105 exit 0 106else 107 sync 108 echo "FAILED" 109 exit 1 110endif 111 112