Monashee Backup
, (*1)
A simple Laravel artisan utility to backup MySQL database to AWS S3 bucket., (*2)
I use it by creating a backup mysql user and attaching that user to all of the databases I want to backup. In a multi database environment it makes it easier to only select those databases that are in production., (*3)
It saves to a temp folder then after uploading to AWS S3 it removes the $database.sql.gz files., (*4)
It also cleans up the S3 folder by removing daily backups from 2 months ago but leaving the first one of the month., (*5)
Events
MonasheeBackupSuccess fires on completion and passes the $databases array, (*6)
MonasheeBackupFail fires on Exception and passes the $e->getTraceAsString(), (*7)
Installation
Requires, (*8)
Install via Composer by adding the following line to the require block of your composer.json file, (*9)
"monashee/backup": "dev-master"
Then run composer update, (*10)
Add this line to the providers array in your app/config/app.php file:, (*11)
'Monashee\Backup\BackupServiceProvider',
Configuration
Create or edit your .env.php file in your root directory. Copy the config settings and edit the fields., (*12)
<?php
return [
'BACKUP_MYSQL_HOST' => 'host',
'BACKUP_MYSQL_USER' => 'user',
'BACKUP_MYSQL_PASSWORD' => 'password',
'BACKUP_MYSQLDUMP_PATH' => '/usr/bin/mysqldump',
'BACKUP_AWS_KEY' => 'key',
'BACKUP_AWS_SECRET' => 'secret',
'BACKUP_S3_BUCKET' => 'bucket',
'BACKUP_S3_REGION' => 'us-west-2',
'BACKUP_STORAGE_PATH' => 'monashee/backup/'
];
AWS S3 Regions http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region, (*13)
Usage
php artisan monashee:backup
Test in console to make sure it runs without errors. I find it easier to create a MySQL user called backup and add that user to all of the databases I want to backup., (*14)
Set a cron job to trigger the command when needed., (*15)
Notes
It uses the mysqldump command for creating the backup. More info mysqldump, (*16)
mysqldump requires at least the SELECT privilege for dumped tables, SHOW VIEW for dumped views, TRIGGER for dumped triggers, and LOCK TABLES if the --single-transaction option is not used. Certain options might require other privileges as noted in the option descriptions., (*17)
To reload a dump file, you must have the same privileges needed to create each of the dumped objects by issuing CREATE statements manually., (*18)
\Monashee\Backup\Dump.php has the mysqldump options, (*19)