Diem plugins syndication

dmSqlBackupPlugin

Creates SQL backups for your project

dmSqlBackupPlugin allows to create SQL backups for your project.
It provides the sql_backup service, and a dm:sql-backup task.
Fully configurable and extensible with new database adapters.
Currently, only a Mysql adapter is available.

Installation

  • In a console, from your project root dir, run:
git clone git://github.com/ornicar/dmSqlBackupPlugin.git plugins/dmSqlBackupPlugin  
  • In config/ProjectConfiguration.class.php, add dmSqlBackupPlugin to the list of enabled plugins:
class ProjectConfiguration extends dmProjectConfiguration
{  
  public function setup()  
  {  
    parent::setup();  
 
    $this->enablePlugins(array(  
      // your enabled plugins  
      'dmSqlBackupPlugin'  
    ));  
  • In a console, from your project root dir, run:
php symfony dm:setup  

Usage

Command line

php symfony dm:sql-backup  

Plan a cron task

For example to run this task all days:
/etc/crontab

@daily www-data /usr/bin/php5 /home/my-project/symfony dm:sql-backup  

Programmatically

$sqlBackup = $this->getService('sql_backup');
$sqlBackup->execute($connection);  

$connection must be an instance of Doctrine_Connection.

Customize

Use the service container configuration file to change sql_backup parameters. It allows to configure the service, add new adapters and override the service class.
config/dm/services.yml

parameters:  
  
  sql_backup.class:       dmSqlBackup  
  sql_backup.adapters:  
    mysql:                dmSqlBackupAdapterMysql  
  sql_backup.options:  
    dir:                  SF_ROOT_DIR/data/dm/backup/sql  
    file_format:          %%db_name%%-%%year%%_%%month%%_%%day%%_%%time%%.sql  
  • Loban Amaan RahmanMarch 11, 2010 4:30 AM

    I've got a couple of suggestions that would make this plugin perfect:

    (1) Add a dm:sql-restore task. I guess it can take which backup to use as an argument.

    (2) Add a menu item + UI in the admin panel to take, list, and restore backups.

    Love the work you've done Thibault D!

  • acai berry juiceAugust 4, 2011 7:34 AM

    Great article, lots of intersting things to digest. Very informative

  • Preferred MortgageAugust 5, 2011 5:54 AM

    Thank you very much for that wonderful article

  • tario gameOctober 10, 2011 12:42 PM

    Great information. It's really useful. Thanks

Add a comment

dmSqlBackupPlugin, created on March 3, 2010 by Thibault D, used by 414 projects

Fork Diem on GitHub