Example #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");
 }
Example #2
0
 /**
  * @return null|Host
  */
 public function getRemoteHost()
 {
     $sourceHost = $this->source->getHost();
     $destinationHost = $this->destination->getHost();
     if (empty($sourceHost)) {
         if (empty($destinationHost)) {
             return NULL;
         } else {
             return $destinationHost;
         }
     }
     return $sourceHost;
 }
Example #3
0
 /**
  * Tests if a given file exists on the remote server
  * @param \Cogeco\Build\Entity\File $file
  * @return bool
  */
 public static function fileExists(File $file)
 {
     // Make sure there is a connection
     if (!$file->isRemote()) {
         echo "Warning: Testing for file existence on local machine rather than a remote one";
         return file_exists($file->getPath());
     }
     $command = '[ -f ' . $file->getPath() . ' ] && echo "1" || echo "0"';
     $ssh = self::connect($file->getHost());
     $output = trim($ssh->exec($command));
     self::checkCmdExceptions($ssh);
     return $output === "1";
 }
Example #4
0
// 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);
// ********************
// *** Move the file to the shared drive