Created
March 16, 2018 12:58
-
-
Save frederickjh/eadfe6ae311a4f6b4015c77fac4a26a9 to your computer and use it in GitHub Desktop.
Robo task runner backup Task and configuration files for Drupal 8, Drush 9 with a composer based workflow.
This file contains hidden or 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 | |
#### Configuration for MEOS Drupal 8 Backups with RoboFile | |
## Site URI | |
$siteuri='example.com'; | |
## Folder where you want backups to be stored remotely. No trailing slashes! | |
$remotebackupbasepath='/home/user/backups/squidixvps'; | |
## Remote backup user and server in the form of user@server | |
## If you have an alias in your ~/.ssh/config file you can use that here too. | |
## NOTE: We do not plan to handle passwords for login. | |
## You will need to setup passwordless login using ssh keys. | |
$remotebackupuserandserver='backupserver'; | |
## Path to default PHP to used | |
## We do this as some jailshells do not run through our .bashrc or .profile files | |
## because of this the environmental variable DRUSH_PHP does not get set. | |
## We will set it in the script if this variable is set. | |
// $defaultpathtophp='/opt/cpanel/ea-php70/root/usr/bin/php'; |
This file contains hidden or 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/ | |
*/ | |
class RoboFile extends \Robo\Tasks | |
{ | |
use \Boedah\Robo\Task\Drush\loadTasks; | |
function backup() | |
{ | |
include 'RoboConfig.php'; | |
$dateofbackup = date('o-m-d-W-w-His'); // yyyy-mm-dd-Week number-day of week-HHMMSS | |
$filename = $siteuri . '-' . $dateofbackup; | |
exec('drush status', $drushinfo); | |
$gitbranch = exec('git rev-parse --abbrev-ref HEAD'); | |
$gitinfo = exec('git describe --always $gitbranch'); | |
$this->stopOnFail(true); | |
$collection = $this->collectionBuilder(); | |
$tmpPath = $collection->tmpDir(); | |
$archiveFile = '/tmp/'. $siteuri . '/' . $filename . '.tar.gz'; | |
$collection->taskFilesystemStack() | |
->taskDrushStack() | |
->drush('sql:dump --result-file=' . $tmpPath . '/' . $filename . '.sql') | |
->drush('drush cr') | |
->drush('drush csex excluded') | |
->run(); | |
// Task to create manifest here | |
$collection->taskWriteToFile($tmpPath . '/' . 'MANIFEST.ini') | |
->line('[Global]') | |
->line('siteuri = ' . $siteuri) | |
->line('datestamp = ' . $dateofbackup) | |
->line('gitbranch = ' . $gitbranch) | |
->line('gitinfo = ' . $gitinfo) | |
->line('generator = MEOS Robo Backup') | |
->line('') | |
->line('[Drush Status]') | |
->lines($drushinfo) | |
->run(); | |
// Copy files to temporary directory in preparation for archiving. | |
$collection->taskCopyDir(['../../private' => $tmpPath . '/private']); | |
$collection->taskCopyDir(['../../shared' => $tmpPath . '/shared']); | |
$collection->taskCopyDir(['../../.dep' => $tmpPath . '/.dep']); | |
$collection->taskCopyDir(['config/excluded' => $tmpPath . '/current/config/excluded']); | |
// Create folder for and then tar.gz archive of backup. | |
$collection->taskFilesystemStack() | |
->mkdir('/tmp/'. $siteuri) | |
->run(); | |
$collection->taskExecStack() | |
->exec('tar --dereference -czf ' . $archiveFile . ' -C ' . $tmpPath . ' .') | |
->completion($this->taskDeleteDir($tmpPath)) | |
->run(); | |
// scp backup to remote backup server. | |
$collection->taskExecStack() | |
->exec('scp ' . $archiveFile . ' ' . $remotebackupuserandserver. ':' . $remotebackupbasepath . '/') | |
->completion($this->taskDeleteDir('/tmp/'. $siteuri)) | |
->run(); | |
$collection->run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment