kernel - More readdirplus deadlock avoidance work
[dragonfly.git] / bin / cpdup / scripts / do_mirror_host
bloba733de3196ebc97d69a74da0f21080ccccd598f4
1 #!/bin/csh
3 # $DragonFly: src/bin/cpdup/scripts/do_mirror_host,v 1.2 2006/09/21 00:18:13 dillon Exp $
5 source params
7 if ( "$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
14 endif
16 set date = `date "+%Y%m%d"`
17 set host = "$argv[1]"
18 set level = "$argv[2]"
20 if ( ! -d $backup_nfs/$host ) then
21 echo "Host not found in $backup_nfs"
22 exit 1
23 endif
24 if ( ! -d $backup_path/mirrors/$host ) then
25 mkdir $backup_path/mirrors/$host
26 endif
28 # Target directory for this backup
30 set target = $host.$date
31 if ( ! -d $backup_path/mirrors/$target ) then
32 mkdir -p $backup_path/mirrors/$target
33 endif
35 set failed = 0
37 # Record log
39 rm -f $backup_path/mirrors/$target/{INPROGRESS,FAILED,SUCCEEDED}
40 if ( -f $backup_path/mirrors/$host.log ) then
41 ln $backup_path/mirrors/$host.log $backup_path/mirrors/$target/INPROGRESS
42 else
43 echo "NO LOG RECORDED" > $backup_path/mirrors/$target/INPROGRESS
44 endif
46 # Iterate subdirectories. Each subdirectory is considered to be a separate
47 # filesystem.
49 foreach fs ( $backup_nfs/$host/* )
50 set dirname = $fs:t
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 ""
90 end
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.
97 if ( $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"
103 else
104 mv $backup_path/mirrors/$target/{INPROGRESS,FAILED}
105 sync
106 echo "FAILED"
107 endif