missing project/build files
[client-tools.git] / src / game / server / database / build / linux / copy_cluster.pl
blob76eee5420bf0bed4a8cab20015bee7902a8b3d14
1 #!/usr/bin/perl
3 use strict;
4 use Getopt::Long;
6 &main;
8 sub main
10 my ($starttime, $endtime);
12 &GetOptions("copycluster","exportcluster","importcluster","createtypes","wipeschema","recompilepackages","help","username:s","password:s","service:s","source:s");
14 if ($::opt_help || ($::opt_source eq "") || !($::opt_copycluster || $::opt_exportcluster || $::opt_importcluster || $::opt_createtypes || $::opt_wipeschema || $::opt_recompilepackages ))
16 print "Usage: copy_cluster.pl [COMMAND] [OPTION]... \n";
17 print "Copy a cluster using Oracle export/import.\n\n";
18 print "******************* WARNING *******************.\n";
19 print "* This utility will delete all existing user *\n";
20 print "* objects in your schema *\n";
21 print "***********************************************.\n";
22 print "\n";
23 print "Commands:\n";
24 print " --help Display these options.\n";
25 print " --copycluster Perform the complete copy to user schema.\n";
26 print "\n";
27 print " --exportcluster Export cluster to file using direct path.\n";
28 print " --importcluster Import cluster from file using direct path.\n";
29 print " --createtypes Recreate oracle typedefs.\n";
30 print " --wipeschema Delete all objects from users schema.\n";
31 print " --recompilepackages Recompile user database packages.\n";
32 print "\n";
33 print "Options:\n";
34 print " --username=NAME Specify the database user name. (Defaults to \$USER.)\n";
35 print " --password=PASSWORD Specify the database password. (Defaults to \"changeme\".)\n";
36 print " --service=NAME Specify the database service name. (Defaults to \"swodb\".)\n";
37 print " --source=NAME Specify the source schema name.\n";
39 print "\n";
41 exit;
44 $starttime = time();
46 print "Start time:\t",scalar localtime($starttime),"\n\n";
48 SWITCH: {
50 if ($::opt_copycluster) { &copycluster; last SWITCH; }
51 if ($::opt_exportcluster) { &exportcluster; last SWITCH; }
52 if ($::opt_importcluster) { &importcluster; last SWITCH; }
53 if ($::opt_createtypes) { &createtypes; last SWITCH; }
54 if ($::opt_wipeschema) { &wipeschema; last SWITCH; }
55 if ($::opt_recompilepackages) { &recompilepackages; last SWITCH; }
56 print "Warning unknown option \n";
57 system("echo Warning unknown command > sqloutput.tmp" );
60 $endtime = time();
61 print "End time:\t",scalar localtime($endtime),"\n\n";
62 print "Elasped time:\t",($endtime - $starttime)," second(s)\n";
66 #=======================================================================
68 #run all the steps at once involved in copying the cluster
69 sub copycluster
71 print "**** STARTING CLUSTER COPY ****\n\n";
72 system ("rm cluster.dmp");
73 print "**** EXPORING CLUSTER ****\n\n";
74 &exportcluster;
75 print "**** DROPPING ALL OBJECTS IN USER SCHEMA ****\n\n";
76 &wipeschema;
77 print "**** RECREATING ORACLE USER TYPES ****\n\n";
78 &createtypes;
79 print "**** IMPORTING CLUSTER ****\n\n";
80 &importcluster;
81 print "**** RECOMPILING USER PACKAGES ****\n\n";
82 &recompilepackages;
83 print "**** CLUSTER COPY COMPLETE ****\n\n";
84 print "Notes:\n\n";
85 print "All packages may not recompile depending the version delta between the cluster packages\n";
86 print " and your user schema packages\n\n";
87 print "You need to sync your game code to a version that will work with the cluster schema\n";
88 print " using perforce and then update the packages using database_update.pl\n\n";
89 print "What version to sync to is up to you depending on what you'd like to test\n\n";
92 #-----------------------------------------------------------------------
94 #export cluster to file using direct path
95 sub exportcluster
97 system ("exp ".&login." file=cluster.dmp owner=$::opt_source direct=y > output.tmp");
100 #-----------------------------------------------------------------------
102 #import cluster from file using direct path
103 sub importcluster
105 system ("imp ".&login." file=cluster.dmp fromuser=$::opt_source touser=".&username." >> output.tmp");
108 #-----------------------------------------------------------------------
110 #wipe all objects in user schema
111 sub wipeschema
113 system (&sqlplus." @../../queries/drop_all_objects.sql >> output.tmp");
116 #-----------------------------------------------------------------------
118 #recompile invalid packages
119 sub recompilepackages
121 system ("./check_objects.sh ".&login." >> output.tmp");
122 system (&sqlplus." \@check_objects.sql >> output.tmp");
125 #-----------------------------------------------------------------------
127 # recreate Oracle typedefs after wipe since typedef can't be imported
128 sub createtypes
130 open (CREATELIST,"ls ../../schema/*.type|");
131 while (<CREATELIST>)
133 print $_;
134 chop;
135 system (&sqlplus." < $_ > /tmp/database_update.tmp");
136 &checkError("/tmp/database_update.tmp");
138 close (CREATELIST);
141 #-----------------------------------------------------------------------
143 # Return oracle username string
144 sub username
146 my ($user);
147 $user=$::opt_username;
148 $user=$ENV{"USER"} if ($user eq "");
150 $user =~ tr/A-Z/a-z/;
152 return "$user";
155 #-----------------------------------------------------------------------
157 # Return oracle password string
158 sub password
160 my ($pwd);
161 $pwd=$::opt_password;
162 $pwd=$ENV{"DB_PASSWORD"} if ($pwd eq "");
163 $pwd="changeme" if ($pwd eq "");
165 return "$pwd";
168 #-----------------------------------------------------------------------
170 # Return oracle service string
171 sub service
173 my ($db);
174 $db=$::opt_service;
175 $db="swodb" if ($db eq "");
177 return "$db";
180 #-----------------------------------------------------------------------
182 # Return oracle login command string
183 sub login
185 return &username."/".&password."\@".&service;
188 #-----------------------------------------------------------------------
190 # Return the sqlplus command string
191 sub sqlplus
193 return "sqlplus ".&login;
196 #-----------------------------------------------------------------------
198 sub checkError
200 my ($filename,$dontdie)=@_;
202 open (CHECKFILE,$filename);
203 while (<CHECKFILE>)
205 if (/ERROR/ || /created with compilation errors/ )
207 print;
208 while (<CHECKFILE>)
210 last if (/Disconnected from Oracle/);
211 print;
213 close CHECKFILE;
214 #system("rm $filename");
215 die unless $dontdie;
216 last;
219 close (CHECKFILE);
220 system("rm -f $filename");