Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyshaw committed Mar 16, 2016
2 parents 31e46b2 + b675468 commit 30c8467
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 8 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ It's design to run on production boxes to create database dumps and upload to Am

It can then be run on local development machines to get latest or specific backup for a project and automatically import it.

Works particularly well when partnered with [mageconfigsync](https://github.com/punkstar/mageconfigsync).

## Motivation

Working on Magento client sites typically requires a fresh copy of the production database in order reduce discrepencies later in the development cycle due to differences between environments. This can be difficult to achieve a number of reasons and either way will slow down development process.
Expand Down Expand Up @@ -122,3 +124,47 @@ Delete old backups from S3.
```
magedbm rm [-r|--region="..."] [-b|--bucket="..."] name file
```


## Development

### Packaging Phar

We use [box project](https://github.com/box-project/box2) for creating a phar. The configuration for which is found in
`box.json`.

To build, change to the project root and run:

```
box build
```

If you run into the following [error](https://github.com/box-project/box2/issues/80):

```
PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): unable to create pipe Too many open files'
```


Then increasing the limit by running this seems to be a solid workaround:

```
ulimit -Sn 4096
```

### Creating Release

After creating a release according to [meanbee standards](http://standards.meanbee.com/tools.html), the phar can be attached to the release on github.

It also needs to be uploaded to the magedbm-releases bucket in Meanbee's S3 account. We upload one version as `magedbm.phar` and another with the version in it `magedbm.1.3.0.phar`.

In order for the self-update command to know about the new release, the manifest.json file (also in the magedbm-releases bucket) requires update. Create a new entry in the releases array to point to the latest version. To create the SHA which is used for valiation upon update run this command:

```
shasum -a 1 ./magedbm.phar
```

For any files uploaded, make sure that they're made public by clicking on Properties so that external uses to Meanbee can access.



15 changes: 15 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"name": "magedbm.phar",
"sha1": "378a6ca3e92f850508900415e2c905387a0d940c",
"url": "https://s3-eu-west-1.amazonaws.com/magedbm-releases/magedbm.1.3.2.phar",
"version": "1.3.2"
},
{
"name": "magedbm.phar",
"sha1": "1830c419f4d7043a15ae88c5ded6bd834b656fc3",
"url": "https://s3-eu-west-1.amazonaws.com/magedbm-releases/magedbm.1.4.0.phar",
"version": "1.4.0"
}
]

4 changes: 2 additions & 2 deletions src/Meanbee/Magedbm/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Application extends \Symfony\Component\Console\Application
{

const APP_NAME = 'Magedbm';
const APP_VERSION = '1.4.0';
const APP_VERSION = '1.4.1';

protected $autoloader;

Expand Down Expand Up @@ -43,4 +43,4 @@ public function setAutoloader($autoloader)

return $this;
}
}
}
16 changes: 12 additions & 4 deletions src/Meanbee/Magedbm/Command/GetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function downloadBackup($file, $s3, $config, $input)
'SaveAs' => $this->getFilePath($file)
));
} catch (NoSuchKeyException $e) {
$this->getOutput()->writeln('<error>File such file found in S3 bucket.</error>');
$this->getOutput()->writeln('<error>No such file found in S3 bucket.</error>');
exit;
}

Expand Down Expand Up @@ -218,8 +218,16 @@ protected function backupMove($file)
{
$filename = $this->getFilePath($file);
$newFilename = getcwd() . '/' . $file;
if (rename($filename, $newFilename)) {
$this->getOutput()->writeln("<info>Downloaded to $newFilename.</info>");

if (!is_writable(getcwd())) {
$this->getOutput()->writeln("<info>Unable to write to current working directory. Check $filename</info>");
return;
}

$result = rename($filename, $newFilename);

if ($result && file_exists($newFilename)) {
$this->getOutput()->writeln("<info>Downloaded to $newFilename</info>");
} else {
$this->getOutput()->writeln("<error>Failed to move backup to current working directory. Check $filename</error>");
}
Expand Down Expand Up @@ -250,4 +258,4 @@ protected function cleanUp()
{
array_map('unlink', glob(self::TMP_PATH . '/*'));
}
}
}
6 changes: 4 additions & 2 deletions src/Meanbee/Magedbm/Command/PutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function maintainDatabaseHistory($input, $output, $s3, $config)
try {
$results = $s3->getIterator(
'ListObjects',
array('Bucket' => $config['bucket'], 'Prefix' => $input->getArgument('name'), 'sort_results' => true)
array('Bucket' => $config['bucket'], 'Prefix' => $input->getArgument('name') . '/', 'sort_results' => true)
);

$results = iterator_to_array($results, true);
Expand Down Expand Up @@ -210,7 +210,7 @@ private function createBackup(InputInterface $input, OutputInterface $output)
$magerun = $this->getMagerun();
$filePath = $this->getFilePath($input);

$stripOptions = $input->getOption('strip') ? : '@development';
$stripOptions = $input->getOption('strip') ?: '@development';

// Exec must be unavailable so use PHP alternative (match output)
$dbHelper = new DatabaseHelper();
Expand Down Expand Up @@ -258,6 +258,7 @@ private function createBackup(InputInterface $input, OutputInterface $output)
'include-tables' => $stripTables,
'no-data' => true,
'add-drop-table' => true,
'skip-triggers' => true,
)
);

Expand All @@ -266,6 +267,7 @@ private function createBackup(InputInterface $input, OutputInterface $output)
$dump = new Mysqldump(sprintf('%s;dbname=%s', $dbHelper->dsn(), $dbName), $username, $password, array(
'exclude-tables' => $stripTables,
'add-drop-table' => true,
'skip-triggers' => true,
));

$dump->start($filePath . '.data');
Expand Down

0 comments on commit 30c8467

Please sign in to comment.