]> andersk Git - moira.git/blob - incremental/afs_rename.pl
Initial revision
[moira.git] / incremental / afs_rename.pl
1 #!/usr/athena/bin/perl
2 # Usage: afs_change \
3 #               oldname oldcell oldtype oldltype oldpath \
4 #               newname newcell newtype newltype newpath
5
6 require "/moira/bin/afs_utils.pl";
7
8 die "$0: Incorrect number of arguments\n" if (@ARGV != 10);
9
10 ($oldname, $oldcell, $oldtype, $oldltype, $oldpath,
11  $newname, $newcell, $newtype, $newltype, $newpath) =
12     @ARGV;
13
14 # Modify the paths, as only the read-write paths are used.
15 $oldpath =~ s:^/afs/([^.]):/afs/.\1:;   # use read-write path
16 $newpath =~ s:^/afs/([^.]):/afs/.\1:;   # use read-write path
17
18 die "Cannot change cells\n" if ($oldcell ne $newcell);
19 die "Can only handle AFS and ERR lockers\n"
20     if (($oldtype !~ /^(AFS|ERR)$/) ||
21         ($newtype !~ /^(AFS|ERR)$/));
22
23 # Lookup volume type
24 ($c = $newcell) =~ s/\./_/g;
25 $vtype = eval "\$vtypes_$c{$newltype}";
26 die "Cannot handle $newltype volumes\n" unless $vtype;
27 $newvname = $vtype . "." . $newname;
28
29 if ($oldtype eq "ERR") {
30     # Lookup volume type for old locker
31     ($c = $oldcell) =~ s/\./_/g;
32     $vtype = eval "\$vtypes_$c{$oldltype}";
33     die "Cannot handle $oldltype volumes\n" unless $vtype;
34     $oldvname = $vtype . "." . $oldname;
35     $oldvname =~ s/[^-A-Za-z0-9_.]//g;  # strip out illegal characters
36
37     if (&check("X" . $oldvname) && &check("Xn." . $oldvname)) {
38         print STDERR "Cannot locate deactivated locker $oldname\n";
39         exit(1) if ($newtype eq "AFS");
40         exit(0);
41     }
42     $newvname = "n." . $newvname if ($oldvname =~ /^Xn\./);
43 } else {
44     $prefix = "";
45
46     open(FS, "$fs lsm $oldpath|");
47     chop($_ = <FS>);
48     close(FS);
49     die "Unable to locate locker $oldname\n" if ($?);
50     ($oldvname = $_) =~ s/^.* volume '.(.*)'$/\1/;
51     die "Unusual mountpoint encountered: $oldpath\n" if ($oldvname =~ /[ :]/);
52     $newvname = "n." . $newvname if ($oldvname =~ /^n\./);
53 }
54
55 $newvname = "X" . $newvname if ($newtype eq "ERR");
56 $newvname =~ s/[^-A-Za-z0-9_.]//g;      # strip out illegal characters
57
58 &run("$fs rmm $oldpath");
59 &run("$vos rename $oldvname $newvname -cell $newcell")
60     if ($oldvname ne $newvname);
61 &run("$vos remove $oldbackup $oldvname.backup -cell $oldcell")
62     if ($oldbackup && $newvname =~ /^n\./);
63 &run("$fs mkm $newpath $newvname")
64     if ($newtype eq "AFS");
65 &release_parent($newpath);
66
67 exit;
68
69
70 sub run
71 {
72     local(@cmd) = @_;
73     system("@cmd >/dev/null");
74     die "@cmd: FAILED\n" if ($?);
75     return 0;
76 }
77
78
79 sub check
80 {
81     local($vname) = @_;
82     local(@vos, @a);
83     
84     open (VOS, "$vos listvldb -name $vname -cell $oldcell 2>/dev/null|");
85     chop(@vos = <VOS>);
86     close(VOS);
87     return 1 if ($?);
88
89     $oldvname = $vname;
90     @a = split(/\s+/, $vos[$[ + 4]);
91     if (($_ = pop @a) eq "valid") {
92         splice(@vos, 0, 6);
93         for (@vos) {
94             ($oldbackup=$_) =~ s/^.*server (.*) partition (.*) RW .*$/\1 \2/
95                 if (/RW Site/);
96         }
97     }
98     return 0;
99 }
100
101 sub release_parent
102 {
103     local($p) = @_;
104
105     $p =~ s:/[^/]+$::;
106     open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
107     chop($_ = <FS>);
108     close(FS);
109     return if ($?);
110
111     local(@tmp) = (split(/ /,$_));
112     &run("$vos release $tmp[$#tmp] -cell $newcell");
113 }
This page took 0.043015 seconds and 5 git commands to generate.