]> git.andy128k.dev Git - ipf.git/commitdiff
dbdump command
authorAndrey Kutejko <andy128k@gmail.com>
Thu, 20 Jun 2013 22:41:54 +0000 (01:41 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Thu, 20 Jun 2013 22:41:54 +0000 (01:41 +0300)
ipf/cli.php
ipf/command/dbdump.php [new file with mode: 0644]

index eff7869f7f90a602b51d413d9b3739fd277615c0..39b97ba36591bdfafa3cfced6c2b73debb86ecbd 100644 (file)
@@ -12,9 +12,10 @@ class IPF_Cli
             new IPF_Command_BuildModels,
             new IPF_Command_BuildContribModels,
             new IPF_Command_Sql,
-            new IPF_Command_DB,
             new IPF_Command_SyncDB,
             new IPF_Command_Fixtures,
+            new IPF_Command_DB,
+            new IPF_Command_DBDump,
             new IPF_Command_CreateSuperUser,
             new IPF_Command_SyncPerms,
         );
diff --git a/ipf/command/dbdump.php b/ipf/command/dbdump.php
new file mode 100644 (file)
index 0000000..2072389
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+class IPF_Command_DBDump
+{
+    public $command = 'dbdump';
+    public $description = 'Dumps database to a file';
+
+    public function run($args=null)
+    {
+        $output = 'dump.sql';
+
+        print "Dumping database to file $output\n";
+
+        $db = IPF_ORM_Manager::getInstance()->connectionParameters(IPF::get('database', IPF::get('dsn')));
+
+        if ($db['scheme'] === 'mysql') {
+            IPF_Shell::call('mysqldump',
+                '-h'.$db['host'],
+                '-u'.$db['username'],
+                '-p'.$db['password'],
+                '-r'.$output,
+                $db['database']);
+        } else {
+            print 'Do not know how to connect to "'.$db['scheme'].'" database.';
+        }
+    }
+}
+