[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 #/bin/sh 2 #********************************************************************************* 3 # The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 # ("License"); You may not use this file except in compliance with the License 5 # The Original Code is: vtiger CRM Open Source 6 # The Initial Developer of the Original Code is vtiger. 7 # Portions created by vtiger are Copyright (C) vtiger. 8 # All Rights Reserved. 9 # 10 # ******************************************************************************** 11 setVariables() 12 { 13 wdir=`pwd` 14 echo 'copying the migrator_backup_connection file to the migrator_connection file' 15 cp -f ../apache/htdocs/vtigerCRM/migrator_backup_connection.php ../apache/htdocs/vtigerCRM/migrator_connection.php 16 chmod 777 ../apache/htdocs/vtigerCRM/migrator_connection.php 17 export diffmac=0 18 } 19 20 checkInstallDir() 21 { 22 bindir=$1 23 retval=1 24 if [ -d $bindir} ] 25 then 26 if [ -f $bindir}/startvTiger.sh -a -f $bindir}/stopvTiger.sh ] 27 then 28 retval=0 29 else 30 echo "No such file $bindir}/startvtiger.sh $bindir}/stopvtiger.sh." 31 echo "Invalid vtiger 4.0.1 directory specified" 32 fi 33 else 34 echo "No such Directory: $bindir" 35 fi 36 return $retval} 37 } 38 39 getvtiger4_0_1_installdir() 40 { 41 cancontinue=false 42 43 while [ $cancontinue != "true" ] 44 do 45 local flag=0 46 while [ $flag -eq 0 ] 47 do 48 echo "" 49 echo "Is 4.0.1 mysql installed in the same machine as 4.2 GA? (Y/N)" 50 echo "" 51 52 read RESPONSE 53 case $RESPONSE in 54 [nN]|[nN][oO]) 55 echo "**********************" 56 echo "**********************" 57 echo "**********************" 58 echo "Please ensure that the mysql server instance for 4.0.1 is running " 59 echo "**********************" 60 echo "**********************" 61 echo "**********************" 62 63 while [ "$macname" = "" ] 64 do 65 echo "Please enter the machine name" 66 read macname 67 done 68 69 while [ "$macport" = "" ] 70 do 71 echo "Please enter the mysql Port Number" 72 read macport 73 done 74 75 while [ "$username}" = "" ] 76 do 77 echo "Please enter the mysql User Name" 78 read username 79 done 80 81 echo "Please enter the mysql Password" 82 read passwd 83 84 while [ "$apache_port_4_2}" = "" ] 85 do 86 echo '' 87 echo "Specify the apache port of the vtiger CRM 4.2" 88 read apache_port_4_2 89 done 90 91 getRemoteMySQLDump $macname $macport $username $passwd 92 export diffmac=1 93 flag=1 94 cancontinue=true 95 ;; 96 97 [yY]|[yY][eE][sS]) 98 echo "" 99 flag=1 100 ;; 101 102 *) echo "invalid option" 103 ;; 104 esac 105 done 106 107 if [ $diffmac} -eq 0 ] 108 then 109 res=0 110 111 while [ "$dir_4_0" = "" ] || [ $res != 0 ] 112 do 113 echo "" 114 echo "Specify the absolute path of the bin directory of the vtiger CRM 4.0.1" 115 echo "(For example /home/test/vtigerCRM4_0_1/bin):" 116 read dir_4_0 117 if [ "$dir_4_0}" = "" ] 118 then 119 echo "Kindly enter a valid value please!" 120 fi 121 122 checkInstallDir $dir_4_0} 123 res=$? 124 ##res stores the result of the previous op 125 cancontinue=true 126 done 127 fi 128 done 129 130 echo "" 131 echo 'The 4.0.1 vtiger CRM installation directory is' $dir_4_0 132 } 133 134 getvtiger4_0_1_data() 135 { 136 scrfile=$dir_4_0}/startvTiger.sh 137 138 while [ "$mysql_host_name_4_0}" = "" ] 139 do 140 echo "" 141 echo "Specify the host name of the vtiger CRM 4.0.1 mysql server" 142 read mysql_host_name_4_0 143 done 144 145 while [ "$apache_port_4_0_1}" = "" ] 146 do 147 echo '' 148 echo "Specify the apache port of the vtiger CRM 4.2" 149 read apache_port_4_0_1 150 done 151 152 mysql_dir=`grep "mysql_dir=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 153 echo 'mysql dir is ' $mysql_dir 154 155 mysql_username=`grep "mysql_username=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 156 echo 'mysql username is ' $mysql_username 157 158 mysql_password=`grep "mysql_password=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 159 echo 'mysql password is ' $mysql_password 160 161 mysql_port=`grep "mysql_port=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 162 echo 'mysql port is ' $mysql_port 163 164 mysql_socket=`grep "mysql_socket=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 165 echo $mysql_socket 166 167 mysql_bundled=`grep "mysql_bundled=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 168 echo $mysql_bundled 169 170 pwd 171 src_file_4_0_1=./startvTiger.sh 172 mysql_dir_4_0_1=`grep "mysql_dir=" $src_file_4_0_1} | cut -d "=" -f2 | cut -d "'" -f2` 173 echo $mysql_dir_4_0_1 174 175 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLHOSTNAME $mysql_host_name_4_0} 176 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLUSERNAME $mysql_username} 177 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLPASSWORD $mysql_password} 178 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLPORT $mysql_port} 179 chmod 777 ../apache/htdocs/vtigerCRM/migrator_connection.php 180 } 181 182 finAndReplace() 183 { 184 fileName=$1 185 var=$2 186 val=$3 187 188 tmpFile=$fileName}.$$ 189 sed -e "s@$var}@$val}@g" $fileName} > $tmpFile} 190 mv -f $tmpFile} $fileName} 191 192 } 193 194 isvtiger_MySQL_Running() 195 { 196 version=$1 197 retval=1 198 echo "select 1" | $mysql_dir}/bin/mysql --user=$mysql_username} --password=$mysql_password} --port=$mysql_port} --socket=$mysql_socket} > /dev/null 199 200 exit_status=$? 201 202 if [ $exit_status -eq 0 ] 203 then 204 echo " " 205 echo "The vtiger CRM $version MySQL server is running" 206 echo " " 207 retval=0 208 fi 209 210 return $retval} 211 } 212 213 checkInput() 214 { 215 checkcharlower=$1 216 checkcharupper=$2 217 correctkey=false 218 219 while [ "$correctkey}" != "true" ] 220 do 221 read char 222 if [ "$char" != "$checkcharlower}" -a "$char" != "$checkcharupper}" ] 223 then 224 echo "Press $checkcharlower} (or) $checkcharupper}" 225 else 226 correctkey=true 227 fi 228 done 229 230 } 231 promptAndCheckMySQL() 232 { 233 version=$1 234 echo "" 235 echo "**************************************************" 236 echo "Mysql server in the directory $mysql_dir is not running at port $mysql_port." 237 echo "Start the vtiger CRM $version mysql server and then Press C to contiunue" 238 echo "**************************************************" 239 echo "" 240 checkInput "c" "C" 241 } 242 243 244 245 246 getRemoteMySQLDump() 247 { 248 machine_name=$1 249 m_port=$2 250 m_uname=$3 251 m_passwd=$4 252 253 echo '' 254 echo '' 255 echo '###########################################################' 256 echo '###########################################################' 257 echo 'replacing the values in the migrator_connection.php file ' 258 echo '###########################################################' 259 echo '###########################################################' 260 echo '' 261 echo '' 262 263 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLHOSTNAME $machine_name} 264 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLUSERNAME $m_uname} 265 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLPASSWORD $m_passwd} 266 finAndReplace ../apache/htdocs/vtigerCRM/migrator_connection.php MYSQLPORT $m_port} 267 chmod 777 ../apache/htdocs/vtigerCRM/migrator_connection.php 268 269 scrfile=./startvTiger.sh 270 mysql_dir=`grep "mysql_dir=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 271 #take the dump of the 4.0.1 mysql 272 echo 'set FOREIGN_KEY_CHECKS=0;' > vtiger4_0_1_dump.txt 273 $mysql_dir}/bin/mysqldump -u $m_uname -h $machine_name --port=$m_port --password=$m_passwd vtigercrm4_0_1 >> vtiger4_0_1_dump.txt 274 275 if [ $? -eq 0 ] 276 then 277 echo 'Data dump taken successfully in vtiger_4_0_1_dump.txt' 278 else 279 echo 'Unable to take the database dump. vtigercrm database may be corrupted' 280 exit 281 fi 282 #this should be the 4.0.1 mysql, so create the bkup database in it 283 $mysql_dir}/bin/mysql -h $machine_name --user=$m_uname --password=$m_passwd --port=$m_port -e "create database vtigercrm_4_0_1_bkp" 284 #dump the 4.0.1 dump into the bkup database 285 $mysql_dir}/bin/mysql -h $machine_name --user=$m_uname --password=$m_passwd --port=$m_port vtigercrm_4_0_1_bkp < vtiger4_0_1_dump.txt 286 287 288 289 290 291 292 293 294 295 296 297 298 wget http://localhost:$apache_port_4_2}/Migrate.php 299 300 echo 'set FOREIGN_KEY_CHECKS=0;' > migrated_vtiger_4_2_dump.txt 301 302 #dump the migrated bkup database to a file 303 304 echo 'about to take the dump of the bkup file and put into the migrated_dump.txt file' 305 306 $mysql_dir}/bin/mysqldump -h $machine_name --user=$m_uname --password=$m_passwd --port=$m_port vtigercrm_4_0_1_bkp >> migrated_vtiger_4_2_dump.txt 307 308 echo 'about to drop the database vtigercrm_4_0_1_bkp' 309 310 #${mysql_dir}/bin/mysql -h $machine_name --user=$m_uname --password=$m_passwd --port=$m_port -e "drop database vtigercrm_4_0_1_bkp" 311 312 } 313 #end of getRemoteMySQLDump 314 315 316 startMySQL() 317 { 318 version=$1 319 if [ "$mysql_bundled" == "false" ] 320 then 321 mysql_running=false 322 while [ "$mysql_running}" != "true" ] 323 do 324 promptAndCheckMySQL $version 325 isvtiger_MySQL_Running $version 326 if [ $? = 0 ] 327 then 328 mysql_running=true 329 fi 330 done 331 else 332 mysql_running=false 333 while [ "$mysql_running}" != "true" ] 334 do 335 echo "vtiger CRM $version Mysql Server is not running." 336 echo "Going to start the vtiger CRM $version mysql server at port $mysql_port" 337 $mysql_dir}/bin/mysqld_safe --basedir=$mysql_dir --datadir=$mysql_dir/data --socket=$mysql_socket --tmpdir=$mysql_dir/tmp --user=root --port=$mysql_port --default-table-type=INNODB > /dev/null & 338 sleep 8 339 isvtiger_MySQL_Running $version 340 if [ $? -ne 0 ] 341 then 342 echo "" 343 echo "*****************************************" 344 echo "Unable to start vtiger CRM $version mysql server." 345 echo "Check whether the port $mysql_port is free." 346 echo "Free the port and press c to continue" 347 echo "*****************************************" 348 echo "" 349 checkInput "c" "C" 350 else 351 mysql_running=true 352 fi 353 done 354 fi 355 356 } 357 358 getdump4_0_1_db() 359 { 360 echo "********************************************" 361 echo "Taking the dump of vtiger CRM 4.0.1 database" 362 echo "*******************************************" 363 echo 'set FOREIGN_KEY_CHECKS=0;' > vtiger_4_0_1_dump.txt 364 $mysql_dir_4_0_1}/bin/mysqldump --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket vtigercrm4_0_1 >> vtiger_4_0_1_dump.txt 365 if [ $? -eq 0 ] 366 then 367 echo 'Data dump taken successfully in vtiger_4_0_1_dump.txt' 368 else 369 echo 'Unable to take the database dump. vtigercrm database may be corrupted' 370 exit 371 fi 372 373 $mysql_dir}/bin/mysql --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket -e "create database vtigercrm_4_0_1_bkp" 374 $mysql_dir}/bin/mysql --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket vtigercrm_4_0_1_bkp < vtiger_4_0_1_dump.txt 375 wget http://localhost:$apache_port_4_0_1}/Migrate.php 376 #${mysql_dir}/bin/mysql --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket vtigercrm_4_0_bkp < migrate_4_0to4_0_1.sql 377 echo 'set FOREIGN_KEY_CHECKS=0;' > migrated_vtiger_4_2_dump.txt 378 $mysql_dir_4_0_1}/bin/mysqldump --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket vtigercrm_4_0_1_bkp >> migrated_vtiger_4_2_dump.txt 379 $mysql_dir}/bin/mysql --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket -e "drop database vtigercrm_4_0_1_bkp" 380 381 } 382 383 384 stopvtiger4_0_1MySQL() 385 { 386 echo "Shutting down the vtiger CRM 4.0.1 mysql server" 387 $mysql_dir}/bin/mysqladmin --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket shutdown 388 echo "vtiger CRM 4.0.1 MySQL server shutdown" 389 } 390 391 getvtiger4_2data() 392 { 393 echo 'in get vtiger 4_2 data ' 394 scrfile=./startvTiger.sh 395 396 echo "" 397 mysql_dir=`grep "mysql_dir=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 398 echo "4.2 dir is$mysql_dir" 399 400 echo "" 401 mysql_username=`grep "mysql_username=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 402 echo "4.2 user name is $mysql_username" 403 404 mysql_password=`grep "mysql_password=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 405 echo "" 406 echo "4.2 password is $mysql_password" 407 408 echo "" 409 mysql_port=`grep "mysql_port=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 410 echo "4.2 port is $mysql_port" 411 412 echo "" 413 mysql_socket=`grep "mysql_socket=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 414 echo "4.2 socket is $mysql_socket" 415 416 echo "" 417 mysql_bundled=`grep "mysql_bundled=" $scrfile} | cut -d "=" -f2 | cut -d "'" -f2` 418 echo "4.2 bundled status is $mysql_bundled" 419 } 420 421 dumpinto4_2db() 422 { 423 $mysql_dir}/bin/mysql --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket -e "drop database vtigercrm4_2" 424 $mysql_dir}/bin/mysql --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket -e "create database if not exists vtigercrm4_2" 425 $mysql_dir}/bin/mysql --user=$mysql_username --password=$mysql_password --port=$mysql_port --socket=$mysql_socket vtigercrm4_2 --force < migrated_vtiger_4_2_dump.txt 2> migrate_log.txt 426 427 if [ $? -eq 0 ] 428 then 429 echo 'vTiger CRM 4.0.1 Data successfully migrated into vtiger CRM 4.2 database vtigercrm4_2' 430 else 431 echo 'Unable to dump data into the vtiger CRM 4.2 database vtigercrm4_2. Check the migrate_log.txt in the $wdir directory' 432 exit 433 fi 434 } 435 436 main() 437 { 438 setVariables $* 439 getvtiger4_0_1_installdir 440 441 if [ $diffmac} -eq 0 ] 442 then 443 getvtiger4_0_1_data 444 isvtiger_MySQL_Running 4_0_1 445 446 if [ $? != 0 ] 447 then 448 startMySQL 4_0_1 449 fi 450 getdump4_0_1_db 451 if [ "$mysql_bundled" == "true" ] 452 then 453 stopvtiger4_0_1MySQL 454 fi 455 fi 456 457 getvtiger4_2data 458 isvtiger_MySQL_Running 4_2 459 if [ $? != 0 ] 460 then 461 startMySQL 4_2 462 fi 463 dumpinto4_2db 464 465 } 466 467 main $*
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |