Skip to content

Commit 7c15dc1

Browse files
committed
Integrate HeyBigname's backup manager package
Thanks Shawn and Mitchell! :)
1 parent 7179027 commit 7c15dc1

File tree

15 files changed

+658
-69
lines changed

15 files changed

+658
-69
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ before_script:
1313

1414
script:
1515
- mkdir -p build/logs
16+
- vendor/bin/phpspec run --verbose --format=dot
1617
- vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml
1718

1819
after_script:

app/Lio/Backup/BackupCreator.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
namespace Lio\Backup;
3+
4+
use BigName\BackupManager\Manager;
5+
6+
class BackupCreator
7+
{
8+
/**
9+
* @var \BigName\BackupManager\Manager
10+
*/
11+
private $manager;
12+
13+
/**
14+
* @var string
15+
*/
16+
private $database;
17+
18+
/**
19+
* @var string
20+
*/
21+
private $destination;
22+
23+
/**
24+
* @param \BigName\BackupManager\Manager $manager
25+
* @param string $connection
26+
* @param string $destination
27+
*/
28+
public function __construct(Manager $manager, $connection, $destination)
29+
{
30+
$this->manager = $manager;
31+
$this->database = $connection;
32+
$this->destination = $destination;
33+
}
34+
35+
/**
36+
* Creates a new database backup
37+
*
38+
* @param string $file Optional filename for the backup file
39+
* @return string
40+
*/
41+
public function create($file = null)
42+
{
43+
$file = $file ?: date('Y-m-d-H-i-s') . '_backup.sql';
44+
45+
$this->manager->makeBackup()->run($this->database, $this->destination, $file, 'gzip');
46+
47+
return $file . '.gz';
48+
}
49+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
namespace Lio\Backup;
3+
4+
use Illuminate\Console\Command;
5+
6+
class BackupCreatorCommand extends Command
7+
{
8+
/**
9+
* The console command name.
10+
*
11+
* @var string
12+
*/
13+
protected $name = 'backup:create';
14+
15+
/**
16+
* The console command description.
17+
*
18+
* @var string
19+
*/
20+
protected $description = 'Creates a new database backup file.';
21+
22+
/**
23+
* @var \Lio\Backup\BackupCreator
24+
*/
25+
private $backup;
26+
27+
/**
28+
* Create a new command instance.
29+
*
30+
* @param \Lio\Backup\BackupCreator $backup
31+
*/
32+
public function __construct(BackupCreator $backup)
33+
{
34+
$this->backup = $backup;
35+
36+
parent::__construct();
37+
}
38+
39+
/**
40+
* Execute the console command.
41+
*
42+
* @return void
43+
*/
44+
public function fire()
45+
{
46+
$file = $this->backup->create();
47+
48+
// Output a message to the user with the generated filename.
49+
$this->info("Backup file \"$file\" was created successfully.");
50+
}
51+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php namespace Lio\ServiceProviders;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
use Lio\Backup\BackupCreator;
5+
use Lio\Backup\BackupCreatorCommand;
6+
7+
class BackupServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Bootstrap the application events
11+
*
12+
* @return void
13+
*/
14+
public function boot()
15+
{
16+
$this->commands('command.backup.creator');
17+
}
18+
19+
/**
20+
* Register the service provider
21+
*
22+
* @return void
23+
*/
24+
public function register()
25+
{
26+
$this->registerBackupCreator();
27+
$this->registerBackupCreatorCommand();
28+
}
29+
30+
/**
31+
* Register the backup creator
32+
*/
33+
protected function registerBackupCreator()
34+
{
35+
$this->app->bindShared('backup.creator', function($app) {
36+
$config = $app['config'];
37+
$database = $config->get('database.default');
38+
$destination = $config->get('backup.destination');
39+
40+
return new BackupCreator($app['BigName\BackupManager\Manager'], $database, $destination);
41+
});
42+
43+
$this->app->alias('backup.creator', 'Lio\Backup\BackupCreator');
44+
}
45+
46+
/**
47+
* Register the backup creator command
48+
*/
49+
protected function registerBackupCreatorCommand()
50+
{
51+
$this->app->bindShared('command.backup.creator', function($app) {
52+
return new BackupCreatorCommand($app['backup.creator']);
53+
});
54+
}
55+
56+
/**
57+
* Get the services provided by the provider
58+
*
59+
* @return array
60+
*/
61+
public function provides()
62+
{
63+
return ['backup.creator', 'command.backup.creator'];
64+
}
65+
}

app/config/app.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@
109109
'Illuminate\View\ViewServiceProvider',
110110
'Illuminate\Workbench\WorkbenchServiceProvider',
111111

112+
'BigName\BackupManager\Integrations\Laravel\BackupManagerServiceProvider',
112113
'McCool\LaravelAutoPresenter\LaravelAutoPresenterServiceProvider',
113-
'McCool\DatabaseBackup\ServiceProviders\LaravelServiceProvider',
114114
'Artdarek\OAuth\OAuthServiceProvider',
115115
'Mews\Purifier\PurifierServiceProvider',
116116
'Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider',
117117
'FruitcakeStudio\ReCaptcha\Support\Laravel\ServiceProvider',
118118

119+
'Lio\ServiceProviders\BackupServiceProvider',
119120
'Lio\ServiceProviders\GithubServiceProvider',
120121
'Lio\ServiceProviders\CommentServiceProvider',
121122
'Lio\ServiceProviders\MarkdownServiceProvider',

app/config/backup.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Backup Storage Destination
8+
|--------------------------------------------------------------------------
9+
|
10+
| Here you may specify which destination should be used to create database
11+
| backups with HeyBigname's BackupManager.
12+
|
13+
*/
14+
15+
'destination' => 's3',
16+
17+
];

app/config/local/backup.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
return ['destination' => 'local'];
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
return [
4+
'development' => [
5+
'type' => 'mysql',
6+
'host' => 'localhost',
7+
'port' => '3306',
8+
'user' => 'root',
9+
'pass' => 'password',
10+
'database' => 'test',
11+
],
12+
'production' => [
13+
'type' => 'postgresql',
14+
'host' => 'localhost',
15+
'port' => '5432',
16+
'user' => 'postgres',
17+
'pass' => 'password',
18+
'database' => 'test',
19+
],
20+
];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
return [
4+
'local' => [
5+
'type' => 'Local',
6+
'root' => storage_path('dumps'),
7+
],
8+
's3' => [
9+
'type' => 'AwsS3',
10+
'key' => getenv('AWS_KEY'),
11+
'secret' => getenv('AWS_SECRET'),
12+
'region' => Aws\Common\Enum\Region::FRANKFURT,
13+
'bucket' => getenv('DATABASE_BACKUP_S3_BUCKET'),
14+
'root' => '',
15+
],
16+
];

app/config/packages/mccool/database-backup/config.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
"laravel/framework": "4.2.*",
77
"artdarek/oauth-4-laravel": "1.0.*",
88
"mccool/laravel-auto-presenter": "2.2.*",
9-
"mccool/database-backup": "1.0.*",
109
"michelf/php-markdown": "1.4.*",
1110
"nickcernis/html-to-markdown": "2.1.*",
1211
"misd/linkify": "1.1.*",
1312
"hashids/hashids": "1.0.*",
1413
"mews/purifier": "1.0.*",
1514
"bugsnag/bugsnag-laravel": "1.1.*",
1615
"fruitcakestudio/recaptcha": "0.2.*",
17-
"guzzlehttp/guzzle": "4.2.*"
16+
"guzzlehttp/guzzle": "4.2.*",
17+
"heybigname/backup-manager": "0.3.*",
18+
"aws/aws-sdk-php": "2.7.*",
19+
"league/flysystem": "0.5.*"
1820
},
1921
"require-dev": {
2022
"phpunit/phpunit": "4.3.*",
21-
"mockery/mockery": "0.9.*"
23+
"mockery/mockery": "0.9.*",
24+
"phpspec/phpspec": "~2.1"
2225
},
2326
"autoload": {
2427
"classmap": [

0 commit comments

Comments
 (0)