Merge branch 'vendor/OPENSSL'
[dragonfly.git] / bin / cpdup / scripts / do_remote_host
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
5 source params
6
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_remote_host <host> <level> > $remote_path/mirrors/<host>.log"
13     exit 1
14 endif
15
16 set host = "$argv[1]"
17 set level = "$argv[2]"
18
19 if ( ! -d $backup_nfs/$host ) then
20     echo "Host not found in $backup_nfs"
21     exit 1
22 endif
23 if ( ! -d $backup_path/mirrors/$host ) then
24     echo "No backup found for $host"
25     exit 1
26 endif
27
28 # Figure out the source directory
29 #
30 set source = `readlink $backup_path/mirrors/$host`
31 if ( "$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
35 endif
36
37 # Figure out the hardlink optimized side directory on
38 # the target.
39 #
40
41 if ( $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
54 endif
55
56 # Figure out the target path and add prefixes
57 #
58 set basename = $source
59 set target = ${remote_host}:${remote_path}/mirrors/${source}
60 set source = $backup_path/mirrors/${source}
61 set hlbase = ${remote_path}/mirrors/${hlbase}
62
63 echo "---------- OFFSITE BACKUP OF $source ---------"
64 echo "SOURCE $source"
65 echo "HLBASE $hlbase"
66 echo "TARGET $target"
67
68 # Do the actual backup
69 #
70
71 set failed = 0
72
73 switch($level)
74 case 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
81 case 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
88 case 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
95 default:
96     echo "UNKNOWN BACKUP LEVEL, USE ONLY 0-2"
97     set failed = 1
98     breaksw
99 endsw
100
101 if ( $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
106 else
107     sync
108     echo "FAILED"
109     exit 1
110 endif
111