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";
24 print " --help Display these options.\n";
25 print " --copycluster Perform the complete copy to user schema.\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";
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";
46 print "Start time:\t",scalar localtime($starttime),"\n\n";
50 if ($::opt_copycluster
) { ©cluster
; 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" );
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
71 print "**** STARTING CLUSTER COPY ****\n\n";
72 system ("rm cluster.dmp");
73 print "**** EXPORING CLUSTER ****\n\n";
75 print "**** DROPPING ALL OBJECTS IN USER SCHEMA ****\n\n";
77 print "**** RECREATING ORACLE USER TYPES ****\n\n";
79 print "**** IMPORTING CLUSTER ****\n\n";
81 print "**** RECOMPILING USER PACKAGES ****\n\n";
83 print "**** CLUSTER COPY COMPLETE ****\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
97 system ("exp ".&login
." file=cluster.dmp owner=$::opt_source direct=y > output.tmp");
100 #-----------------------------------------------------------------------
102 #import cluster from file using direct path
105 system ("imp ".&login
." file=cluster.dmp fromuser=$::opt_source touser=".&username
." >> output.tmp");
108 #-----------------------------------------------------------------------
110 #wipe all objects in user schema
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
130 open (CREATELIST
,"ls ../../schema/*.type|");
135 system (&sqlplus
." < $_ > /tmp/database_update.tmp");
136 &checkError
("/tmp/database_update.tmp");
141 #-----------------------------------------------------------------------
143 # Return oracle username string
147 $user=$::opt_username
;
148 $user=$ENV{"USER"} if ($user eq "");
150 $user =~ tr/A-Z/a-z/;
155 #-----------------------------------------------------------------------
157 # Return oracle password string
161 $pwd=$::opt_password
;
162 $pwd=$ENV{"DB_PASSWORD"} if ($pwd eq "");
163 $pwd="changeme" if ($pwd eq "");
168 #-----------------------------------------------------------------------
170 # Return oracle service string
175 $db="swodb" if ($db eq "");
180 #-----------------------------------------------------------------------
182 # Return oracle login command string
185 return &username
."/".&password
."\@".&service
;
188 #-----------------------------------------------------------------------
190 # Return the sqlplus command string
193 return "sqlplus ".&login
;
196 #-----------------------------------------------------------------------
200 my ($filename,$dontdie)=@_;
202 open (CHECKFILE
,$filename);
205 if (/ERROR/ || /created with compilation errors/ )
210 last if (/Disconnected from Oracle/);
214 #system("rm $filename");
220 system("rm -f $filename");