php Jason用于从Pantheon中提取数据库和文件的Robo脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Jason用于从Pantheon中提取数据库和文件的Robo脚本相关的知识,希望对你有一定的参考价值。

<?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');
<?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');
    }
}

以上是关于php Jason用于从Pantheon中提取数据库和文件的Robo脚本的主要内容,如果未能解决你的问题,请参考以下文章

利用多元线性回归法,从大量数据中提取五个因变量来预测一个自变量—Jason niu

sh 在非Multidev环境中部署到Composer Drupal 8到Pantheon。这在将代码从发布分支推送到Pantheon d时非常有用

提取 MySQL Blob 并添加到 PHP 数组?

从 MYSQL 数据库中提取 URL 时,我的 PHP cURL 函数不起作用

用于从切换列表中提取基于域的电子邮件的PHP脚本

从字符串正则表达式 PHP 中提取数值 [关闭]