Last active
August 21, 2018 15:33
-
-
Save megclaypool/9b99d16c1a9dabe52e6cc23a43f8233f to your computer and use it in GitHub Desktop.
Jason's Robo Script for Pulling Database & Files From Pantheon Put copies of RoboFile.php and RoboLocal.php in your site's root directory. Edit RoboLocal.php with the variables appropriate to the specific site and your local dev environment (uncomme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is project's console commands configuration for Robo task runner. | |
* | |
* @see http://robo.li/ | |
*/ | |
if (file_exists(dirname(__FILE__) . '/RoboLocal.php') && !isset($_ENV['PANTHEON_ENVIRONMENT'])): | |
include(dirname(__FILE__) . '/RoboLocal.php'); | |
global $config; | |
print_r($config); | |
endif; | |
class RoboFile extends \Robo\Tasks { | |
/** | |
* Gets the database from Pantheon. | |
*/ | |
function pull() { | |
$env = ROBO_SITENAME . '.' . ROBO_ENV; | |
$this->say('Creating backup on Pantheon.'); | |
$this->taskExec('terminus')->args('backup:create', $env, '--element=db')->run(); | |
$this->say('Downloading backup file.'); | |
$this->taskExec('terminus')->args('backup:get', $env, '--to=db.sql.gz', '--element=db')->run(); | |
$this->say('Unzipping and importing data'); | |
$mysql = "mysql"; | |
if(defined('ROBO_DB_USER')) { | |
$mysql .= " -u " . ROBO_DB_USER; | |
} | |
if(defined('ROBO_DB_PASS')) { | |
$mysql .= " -p" . ROBO_DB_PASS; | |
} | |
$mysql .= ' ' . ROBO_DB; | |
$this->_exec('gunzip < db.sql.gz | ' . $mysql); | |
$this->say('Data Import complete, deleting db file.'); | |
$this->_exec('rm db.sql.gz'); | |
} | |
function pullfiles() { | |
$env = ROBO_SITENAME . '.' . ROBO_ENV; | |
$download = 'files_' . ROBO_ENV; | |
$this->say('Creating files backup on Pantheon.'); | |
$this->taskExec('terminus')->args('backup:create', $env, '--element=files')->run(); | |
$this->say('Downloading files.'); | |
$this->taskExec('terminus')->args('backup:get', $env, '--to=files.tar.gz', '--element=files')->run(); | |
$this->say('Unzipping archive'); | |
$this->taskExec('tar')->args('-xvf', './files.tar.gz')->run(); | |
$this->say('Copying Files'); | |
$this->_copyDir($download, ROBO_FILES_DIR); | |
$this->say('Removing downloaded Files.'); | |
$this->_exec("rm -rf ./$download"); | |
$this->_exec('rm ./files.tar.gz'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('ROBO_DB', 'database_name'); | |
define('ROBO_DB_USER', 'root'); | |
// define('ROBO_DB_PASS', 'root'); | |
define('ROBO_SITENAME', 'site_name'); | |
define('ROBO_ENV', 'dev'); | |
// If it's a regular WordPress site: | |
// define('ROBO_FILES_DIR', 'wp-content/uploads'); | |
// If it's a Bloom Box WordPress site: | |
// define('ROBO_FILES_DIR', 'web/wp-content/uploads'); | |
// If it's a Drupal site: | |
// define('ROBO_FILES_DIR', 'sites/default/files'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment