1#!/bin/csh 2# 3# $DragonFly: src/bin/cpdup/scripts/do_mirror_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_mirror_host <host> <level> > $backup_path/mirrors/<host>.log" 13 exit 1 14endif 15 16set date = `date "+%Y%m%d"` 17set host = "$argv[1]" 18set level = "$argv[2]" 19 20if ( ! -d $backup_nfs/$host ) then 21 echo "Host not found in $backup_nfs" 22 exit 1 23endif 24if ( ! -d $backup_path/mirrors/$host ) then 25 mkdir $backup_path/mirrors/$host 26endif 27 28# Target directory for this backup 29# 30set target = $host.$date 31if ( ! -d $backup_path/mirrors/$target ) then 32 mkdir -p $backup_path/mirrors/$target 33endif 34 35set failed = 0 36 37# Record log 38# 39rm -f $backup_path/mirrors/$target/{INPROGRESS,FAILED,SUCCEEDED} 40if ( -f $backup_path/mirrors/$host.log ) then 41 ln $backup_path/mirrors/$host.log $backup_path/mirrors/$target/INPROGRESS 42else 43 echo "NO LOG RECORDED" > $backup_path/mirrors/$target/INPROGRESS 44endif 45 46# Iterate subdirectories. Each subdirectory is considered to be a separate 47# filesystem. 48# 49foreach fs ( $backup_nfs/$host/* ) 50 set dirname = $fs:t 51 52 echo "Backing up $fs" 53 if ( ! -d $backup_path/mirrors/$target/$dirname ) then 54 mkdir -p $backup_path/mirrors/$target/$dirname 55 endif 56 if ( -f $fs/NOT_MOUNTED ) then 57 echo "NOT MOUNTED" 58 set failed = 1 59 continue 60 endif 61 switch ( $level ) 62 case 0: 63 echo "cpdup -i0 -s0 -I $fs $backup_path/mirrors/$target/$dirname" 64 cpdup -i0 -s0 -I $fs $backup_path/mirrors/$target/$dirname 65 if ( $status != 0 ) then 66 set failed = 1 67 endif 68 breaksw 69 case 1: 70 echo "cpdup -f -i0 -s0 -I -H $backup_path/mirrors/$host/$dirname $fs $backup_path/mirrors/$target/$dirname" 71 cpdup -f -i0 -s0 -I -H $backup_path/mirrors/$host/$dirname $fs $backup_path/mirrors/$target/$dirname 72 if ( $status != 0 ) then 73 set failed = 1 74 endif 75 breaksw 76 case 2: 77 echo "cpdup -i0 -s0 -I -H $backup_path/mirrors/$host/$dirname $fs $backup_path/mirrors/$target/$dirname" 78 cpdup -i0 -s0 -I -H $backup_path/mirrors/$host/$dirname $fs $backup_path/mirrors/$target/$dirname 79 if ( $status != 0 ) then 80 set failed = 1 81 endif 82 breaksw 83 default: 84 echo "UNKNOWN BACKUP LEVEL, USE ONLY 0-2" 85 set failed = 1 86 breaksw 87 endsw 88 sync 89 echo "" 90end 91 92# If we succeeded then set up a softlink so a higher level incremental 93# backup can locate the most recent version of the previous level, 94# another so we can locate the most recent backup period, and also 95# rename the log file. 96# 97if ( $failed == 0 ) then 98 rm -f $backup_path/mirrors/$host 99 ln -s "$host.$date" $backup_path/mirrors/$host 100 mv $backup_path/mirrors/$target/{INPROGRESS,SUCCEEDED} 101 sync 102 echo "SUCCEEDED" 103else 104 mv $backup_path/mirrors/$target/{INPROGRESS,FAILED} 105 sync 106 echo "FAILED" 107endif 108 109