spanjeta / yii2-backup Goto Github PK
View Code? Open in Web Editor NEWDatabase Backup and Restore functionality module extention for Yii2.
License: Apache License 2.0
Database Backup and Restore functionality module extention for Yii2.
License: Apache License 2.0
After success install shown errors "Undefined variable: dataArray"
$dataProvider = new ArrayDataProvider(['allModels'=>$dataArray]);
Instead return '', maybe should change to null in order avoid error when restore the backup
cli exception looks like this
Exception 'yii\db\Exception' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group' at line 1
The SQL being executed was: SHOW CREATE TABLE group'
in /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/db/Schema.php:636
Error Info:
Array
(
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group' at line 1
)
Stack trace:
#0 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/db/Command.php(930): yii\db\Schema->convertException(Object(PDOException), 'SHOW CREATE TAB...')
#1 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/db/Command.php(376): yii\db\Command->queryInternal('fetch', NULL)
#2 /home/vagrant/Code/linet-admin/vendor/spanjeta/yii2-backup/helpers/MysqlBackup.php(107): yii\db\Command->queryOne()
#3 /home/vagrant/Code/linet-admin/vendor/spanjeta/yii2-backup/commands/BackupController.php(46): spanjeta\modules\backup\helpers\MysqlBackup->getColumns('group')
#4 [internal function]: spanjeta\modules\backup\commands\BackupController->actionCreate()
#5 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#6 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#7 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/console/Controller.php(128): yii\base\Controller->runAction('create', Array)
#8 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/base/Module.php(523): yii\console\Controller->runAction('create', Array)
#9 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('backup/backup/c...', Array)
#10 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('backup/backup/c...', Array)
#11 /home/vagrant/Code/linet-admin/vendor/yiisoft/yii2/base/Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#12 /home/vagrant/Code/linet-admin/yii(17): yii\base\Application->run()
#13 {main}
See
https://dev.mysql.com/doc/refman/5.5/en/keywords.html for reserved keywords
I needed to add a download button to the _list.php
In the DefaultController.php controller I added
/* Added by CARDA Consultants Inc., Daniel Pineault */
public function actionDownload()
{
$file=Yii::$app->request->get('file');
$path=Yii::$app->request->get('path');
if (file_exists($path.$file)) {
return Yii::$app->response->sendFile($path.$file);
} else {
throw new \yii\web\NotFoundHttpException("{$file} is not found!");
}
}
Then I modified the _list.php view files as follows
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
echo GridView::widget ( [
'id' => 'install-grid',
'dataProvider' => $dataProvider,
'columns' => array (
'name',
'size:shortSize',
'create_time:datetime',
array (
'header' => 'Actions',
'class' => 'yii\grid\ActionColumn',
'template' => '{restore} {download} {delete}', /* Modified by CARDA Consultants Inc., Daniel Pineault */
'buttons' => [
'delete' => function ($url, $model) {
return Html::a ( '<span class="glyphicon glyphicon-remove"></span>', $url, [
'title' => Yii::t ( 'app', 'Delete this backup' ) ,
'data' => [
'confirm' => 'Are you sure you want to delete this backup?', /* Added by CARDA Consultants Inc., Daniel Pineault */
'method' => 'post',
],
] );
},
'restore' => function ($url, $model) {
return Html::a ( '<span class="glyphicon glyphicon-save"></span>', $url, [
'title' => Yii::t ( 'app', 'Restore this backup' ) ,
'data' => [
'confirm' => 'Are you sure you want to restore this version of your database and permanently crush any existing data?', /* Added by CARDA Consultants Inc., Daniel Pineault */
'method' => 'post',
],
] );
},
/* Added by CARDA Consultants Inc., Daniel Pineault */
'download' => function ($url, $model) {
return Html::a ( '<span class="glyphicon glyphicon-cloud-download"></span>', $url, [
'title' => Yii::t ( 'app', 'Download this backup' ),
'data-method'=>'post',
] );
}
],
'urlCreator' => function ($action, $model, $key, $index) {
$url = Url::toRoute ( [
'default/' .$action,
'file' => $model ['name'] ,
'path'=>\Yii::getAlias('@backend').'/db/' /*Added by CARDA Consultants Inc., Daniel Pineault */
] );
return $url;
}
)
)
] );
?>
Hopefully this can help someone else, and might be a feature worth adding.
Also, I'd recommend changing the header' => 'Delete DB', to perhaps 'header' => 'Actions' as 'Delete DB' isn't accurate since it has multiple buttons.
I have made several backups with this extension, and they seemed to work.
Today I needed to perform a restore and I can't. It always errs giving memory errors. I've pushed the memory allocation to 4GB and still can't handle the restore?!
Then I decided to take the sql file and simply import it. 4 hrs to process in PHPMyAdmin and it didn't work. Using the mysql command line I get back errors relating to the fact that it seems to have converted all the NULLs to 0 or '' making the backup useless.
Hopefully you can address these issues, give some ability to configure certain settings, but for now this extension is not ready for real-world use.
Once database is exported, data is being shown in the sql file but the data is not being inserted upon import into the new database.
Hello!
Thank you for your extension.
Can you make some modification of your DefaultController.php ???
Also it would be good if you add file extension validation in UploadForm.php
[['file'], 'file', 'extensions' => 'sql'],
thank you
You probably have 1.1 installed and in your Path so it's working for you. CHtml, CHttpException, and CUploadedFile need to be changed to the 2.x equivalents.
The use statements for the applicable files need to be included in the controller.
yii\web\HttpException
yii\web\UploadedFile
yii\helpers\Html
hi, the generated backup file change the null values from the original database to empty strings, the function getdata from default controller cointains the error
$itemNames = array_map("addslashes", $itemNames);
change null => ""
im fix this with a custom addslashes
public function addslashesFix($val)
{
if ($val === null)
{
return null;
}
else
{
return "$val";
}
}
and $valueString = join("','", $itemValues);
has the same problem.
i change for json_encode
and reemplace [] for ()
this is my work around
foreach ($dataReader as $data)
{
$itemNames = array_keys($data);
$itemNames = array_map("app\utiles\Backup::addslashesFix", $itemNames);
$items = join('`,`', $itemNames);
$itemValues1 = array_values($data);
$itemValues2 = array_map("app\utiles\Backup::addslashesFix", $itemValues1);
$valueString1 = json_encode($itemValues2);
$valueString2 = str_replace("[", "(", $valueString1);
$valueString3 = str_replace("]", ")", $valueString2);
$values = "\n" . $valueString3;
if ($values != "")
{
$data_string .= "INSERT INTO `$tableName` (`$items`) VALUES" . rtrim($values, ",") . ";" . PHP_EOL;
}
}
sorry for my english.
thanks for your code.
Hello,
Please advise if this is ready for testing, it's showing a number of errors on testing
Regards,
Adam
Hi,
I have an error bellow when create backup, I used postgresql.
`Database Exception – yii\db\Exception
SQLSTATE[42704]: Undefined object: 7 ERROR: unrecognized configuration parameter "tables"
The SQL being executed was: SHOW TABLES
Error Info: Array
(
[0] => 42704
[1] => 7
[2] => ERROR: unrecognized configuration parameter "tables"
)
↵
Caused by: PDOException
SQLSTATE[42704]: Undefined object: 7 ERROR: unrecognized configuration parameter "tables"`
help please,
thanks
Rino
Hi
I'm trying to use this extension to backup and restore my system but I need to change the tables that should be ignored when the actionClear function is executed and I do not see the option in the configuration that allows me to do it...
I need it because when I give restore to the database it gives the following sql error
Database Exception – yii\db\Exception
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
The SQL being executed was: SELECT * FROM `auth_assignment` WHERE `user_id`='1'
the delete action controller ask for an id, but your delete link gives file para. It does not work here.
Change the _list.php view as
$url = Url::toRoute(['default/delete','id'=>$model['id']]);
works for me.
The software delete tables, create tables but not insert. Maybe the '2' instead 2 for integer data like id is no working.
PHP 7.2
If Views exist in the database an error occurs in helpers\MysqlBackup.php because "SHOW TABLES" also lists Views.
Line 62 is now:
$sql = 'SHOW TABLES';
it should be
$sql = "SHOW FULL TABLES where Table_Type != 'VIEW'";
so that only Tables get scripted and saved...
Later on the scripting of Views but not their content could be added... ;-)
Regards
Karl
the exception is :
Getting unknown property: yii\web\View::actions
spanjeta?did you try in yii2 basic template or other template successfully?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.