Beispiel #1
0
 /**
  * @param \Cogeco\Build\Entity\Database $db
  * @param \Cogeco\Build\Entity\File $dumpFile
  * @param $dbName
  * @param array $tables
  * @throws \Cogeco\Build\Exception
  */
 public static function mysqlDump(Database $db, $dbName, array $tables = array(), File $dumpFile)
 {
     if (!is_array($tables) || count($tables) === 0) {
         $tablesParam = '';
     } else {
         $tablesParam = explode(' ', $tables) . ' ';
     }
     // Presentation
     self::log("- Getting dump of {$dbName}");
     if ($db->isRemote()) {
         Task::log(" from {$db->host->hostname}");
     }
     self::log("\n");
     // For use when converting a dump to SQLite
     // --compatible=ansi --skip-extended-insert --compact
     // Build the command
     $cmd = Config::get('mysqldump.bin') . " -vf -P {$db->port}";
     if ($db->isRemote()) {
         $cmd .= " -h {$db->host->hostname}";
     }
     // Create the folder if it doesn't exist already
     FileSystemTask::mkdir($dumpFile->dir->getPath());
     $cmd .= " -u {$db->account->username} -p{$db->account->password} {$dbName} {$tablesParam}| sed '/^\\/\\*\\!50013 DEFINER/d' > {$dumpFile->getPath()}";
     //$cmd .= " --result-file={$dumpFile->getPath()} -u {$db->account->username} -p{$db->account->password} {$dbName} {$tablesParam} 2>&1";
     self::runCmd($cmd);
     self::log("\n");
 }
Beispiel #2
0
// *******************************
Config::enableLogging();
// ********************
// *** Initial output
//
Task::log("\n---------------------------------------\n");
Task::log("-------- Sync database\n\n");
// Prompt for user password, if it's not hardcoded
CliTask::promptAccountPassword($cogecoAccount);
// ********************
// Prompt user input
//
// Prepare a list of possible databases to sync from
$dbList = array($localPublicDb, $localPublicUBCDb, $localPublicPromo, $localPublicGBIncrease, $localDevPhoenixDb, $devPublicDb, $dev2PublicDb, $dev3PublicDb, $dev4PublicDb, $uatPublicDb, $preprodPublicDb);
// Prompt user to input a source database
$sourceDb = CliTask::promptDatabase($dbList, 'Choose a source database:');
Task::log("You chose " . $sourceDb->getDbName() . " on " . $sourceDb->getHost()->getHostname() . "\n\n");
if (($key = array_search($sourceDb, $dbList)) !== false) {
    unset($dbList[$key]);
}
// Prepare a list of possible databases to sync to
$destinationDb = CliTask::promptDatabase($dbList, 'Choose a destination database:');
Task::log("You chose " . $destinationDb->getDbName() . " on " . $destinationDb->getHost()->getHostname() . "\n\n");
CliTask::promptQuit('Continue? [y/n]: ');
// Dump DB to an sql script
$tmpDumpFile = new File(SCRIPT_DB_DIR, $sourceDb->getHost()->getHostname() . '-' . $sourceDb->getDbName() . '-' . Config::get('datetime.slug') . '.sql');
MysqlTask::mysqlDump($sourceDb, $sourceDb->getDbName(), array(), $tmpDumpFile);
// Import DB from the sql script
MysqlTask::importDump($destinationDb, $tmpDumpFile->getPath(), $destinationDb->getDbName());
// Delete the temporary script
//unlink($tmpDumpFile->getPath());
//	CliTask::promptQuit('Deploying to production! Continue? [y/n]: ');
//}
// Prompt for user password, if it's not hardcoded
CliTask::promptAccountPassword($cogecoAccount);
// ********************
// *** Checkout
//
SvnTask::checkoutClean($workingCopy, $revisionToCheckOut, 0);
SvnTask::createManifestFile($workingCopy, FALSE, TRUE);
// ********************
// *** Dump DB
//
Task::log("\n- Deploy schema {$sourceDbSchema} from {$sourceDb->host->hostname} ");
Task::log("to {$destinationDbSchema} on {$destinationDb->getHost()->hostname}\n\n");
//
$tmpDumpFile = new File(SCRIPT_DIR . '/db', "{$sourceDbSchema}-" . Config::get('datetime.slug') . '.sql');
MysqlTask::mysqlDump($sourceDb, $sourceDbSchema, array(), $tmpDumpFile);
// ********************
// *** Prep sync to intermediate remote location
//
Task::log("- Syncing revision {$workingCopy->info->commitRevision} with {$syncDestinationDir1->getPath()} on {$syncDestinationDir1->getHost()->hostname}\n\n");
//
FileSyncTask::sync($rsyncOptions1);
// ********************
// *** Deploy
//
TimerTask::start();
// Import DB
MysqlTask::importDump($destinationDb, $tmpDumpFile->getPath(), $destinationDbSchema);
//
Task::log("- Syncing intermediate directory {$syncDestinationDir1->path} with {$syncDestinationDir2->path}\n\n");
Beispiel #4
0
 /**
  * Gets the Expect command tempalte the rsyn will run in to automate the interactive SSH password
  * @return string
  */
 private static function getExpectCommandTemplate()
 {
     return Config::get('expect.bin') . ' ' . Cygwin::cygPath(BUILD_ROOT_DIR) . '/source/expect/pass.exp "%s" "%s"';
 }
Beispiel #5
0
 /**
  * @param $message
  */
 public static function log($message)
 {
     if (self::$muteOutput || empty($message)) {
         return;
     }
     // Output to console/screen/web page/etc
     if (IS_CLI) {
         echo $message;
     } else {
         echo nl2br($message);
     }
     // Output to log file
     if (Config::get('logging.enabled')) {
         // Init the file handle if not done already
         if (self::$logFileHandle === NULL) {
             self::initLogFile();
         }
         self::writeLog($message);
     }
     flush();
 }
Beispiel #6
0
 /**
  * @param $workingCopy
  * @param int $revision
  * @throws \Cogeco\Build\Exception
  */
 public static function update($workingCopy, $revision = 0)
 {
     $revision = (int) $revision;
     $revisionToUpdate = '';
     if ($revision > 0) {
         $revisionToUpdate = "-r{$revision} ";
     }
     self::log("- Updating to ");
     if ($revision > 0) {
         self::log("revision {$revision}\n");
     } else {
         self::log("head revision\n");
     }
     $cmd = Config::get('svn.bin') . " update {$workingCopy->dir->getPath()} {$revisionToUpdate}" . "--username {$workingCopy->account->username} " . "--password {$workingCopy->account->password} " . "--config-option config:miscellany:use-commit-times=yes " . "--non-interactive --trust-server-cert --no-auth-cache 2>&1";
     self::runCmd($cmd);
     self::log("\n");
 }
Beispiel #7
0
// Use test for testing the script or prod for production use
// Common configs for test/prod
// Prod setup
if ($build === 'prod') {
    $remoteFileOld = new File('/var/www/prod/logs/', 'orders.log', $prodHost);
    $sendOrdersEmail->to = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
} else {
    $remoteFileOld = new File('/var/www/prod/logs/', 'orders2.log', $prodHost);
}
// Common configs for test/prod
$destinationDirPath = '\\eBusiness_Cust_Data_Mngt\\Orders_Archives';
$destDirPathPrefix = '\\\\mtl-fs1\\dept';
$destDirPathPrefixCygwin = 'S:';
$sharedDestinationDir = $destDirPathPrefix . $destinationDirPath;
$localDestinationDir = $destDirPathPrefixCygwin . $destinationDirPath;
$remoteFileNew = new File($remoteFileOld->dir, 'orders_' . Config::get('datetime.slug') . '.log');
$destinationFile = new File($localDestinationDir, $remoteFileNew->name);
$rsyncOptions = new RsyncOptions($remoteFileNew, $destinationFile);
$rsyncOptions->chmod('u=rw,g=rw,o=');
// *******************************
// Start the build script
// *******************************
Config::enableLogging();
// ********************
// *** Initial output
//
Task::log("\n---------------------------------------\n");
Task::log("- Move cogeco.ca orders.log to secured shared drive\n\n");
// Prompt for user password, if it's not hardcoded
CliTask::promptAccountPassword($cogecoAccount);
// ********************