-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_groups_from_server_to_server.pl
More file actions
121 lines (112 loc) · 4.16 KB
/
move_groups_from_server_to_server.pl
File metadata and controls
121 lines (112 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/perl -w
unshift (@INC,"/home/scriptid/scripts/BACKUPS/SUBROUTINES");
require update_clients_group;
require copy_group;
require copy_client;
require copy_schedule;
$date = `/usr/bin/date '+%y%m%d%H%M%S'`;
chomp $date;
open (RAP,">>/home/scriptid/scripts/BACKUPS/RAP/GroupMove_RAP_$date.log") or die "Could not open /home/scriptid/scripts/BACKUPS/RAP/GroupMove_RAP_$date.log\n";
print "\n\nThis utility is used to move all the clients in a group from one backup\n";
print "\t server to another\n\n";
# What is the source server
print "Enter the name of the source backup server: ";
$source = <STDIN>;
chomp $source;
print "Enter the name of the destination backup server: ";
$destination = <STDIN>;
chomp $destination;
print "Enter a search field to limit the number of groups displayed: ";
$search = <STDIN>;
chomp $search;
# Present a list of groups on the source server
print "\n\nCreating list of groups on source server $source\n\n";
$nsrpass = "\. type: NSR group'\n'show name'\n'print";
(@return) = `/usr/bin/echo $nsrpass | /usr/sbin/nsradmin -s $source -i -`;
foreach $val (@return) {
next if $val =~ /Current query set/;
next if $val =~ /^\s+$/;
$val =~ s/^\s+name: //;
$val =~ s/\;$//;
chomp $val;
if ($val =~ /$search/) {
$source_group{$val} = 1;
print "$val\n";
}
}
# Get a list of groups on the destination server
print "\n\nCreating list of groups on destination server $destination\n\n";
$nsrpass = "\. type: NSR group'\n'show name'\n'print";
(@return) = `/usr/bin/echo $nsrpass | /usr/sbin/nsradmin -s $destination -i -`;
foreach $val (@return) {
next if $val =~ /Current query set/;
next if $val =~ /^\s+$/;
$val =~ s/^\s+name: //;
$val =~ s/\;$//;
chomp $val;
if ($val =~ /$search/) {
$destination_group{$val} = 1;
}
}
NEWGROUP:
(@groups) = keys %source_group;
print "NEWGROUP $#groups\n";
print "Enter the name of the group to be moved, all, or exit: ";
$group = <STDIN>;
chomp $group;
if (lc $group =~ /exit/) {exit};
if (lc $group !~ /all/) {
if (defined $destination_group{$group}) {
undef @groups;
print "Just working on one group, $group\n";
push (@groups,$group);
} else {
if (!defined $source_group{$group} ) {
# Source group doesn't exist
print "The group you entered $group is not on the $source server\n";
print "Reenter the group name\n";
goto NEWGROUP;
}
}
}
# Determine if client needs to be created on destination server
print "\n\nCreating list of clients on destination server $destination\n\n";
$nsrpass = "\. type: NSR client'\n'show name'\n'print";
(@return) = `/usr/bin/echo $nsrpass | /usr/sbin/nsradmin -s $destination -i -`;
foreach $val (@return) {
next if $val =~ /Current query set/;
next if $val =~ /^\s+$/; # Take out blank lines
$val =~ s/^\s+name: //; # Strip off everything in front of client name
$val =~ s/\;$//; # Take off training semi colon
chomp $val; # Take off end of line
$destination_client{$val} = 1; # Save client name in HASH
}
foreach $group (@groups) {
print "Checking group $group\n";
if (!defined $destination_group{$group}) {
print "Group $group doesn't exist on $destination so it will be copied\n";
copy_group($source, $destination,$group);
}
print RAP "INFO: Adding clients to $destination from $source for group $group\n";
$nsrpass = "\. type: NSR client\\;group:$group'\n'show name'\n'print'\n'";
#print "NSRPASS: $nsrpass\n";
print "/usr/bin/echo $nsrpass | /usr/sbin/nsradmin -s $source -i - \n";
(@return) = `/usr/bin/echo $nsrpass | /usr/sbin/nsradmin -s $source -i - `;
foreach $val (@return) {
next if $val =~ /Current query set/;
last if $val =~ /No resources found for query/;
next if $val =~ /^\s+$/;
$val =~ s/^\s+name: //;
$val =~ s/\;$//;
chomp $val;
if (defined $destination_client{$val}) {
print RAP "Adding client $val to $group on $destination\n";
print "Adding client $val to $group on $destination\n";
update_clients_group ($destination, $val, $group);
} else {
# Copy the client
copy_client($source,$destination,$val);
}
}
}
goto NEWGROUP;