This is a simple module for full database Backup/Restore. I have been using it for all my apps for quite sometime now. It saves lot of time.
I have enabled basic access control so you can use it on live websites.
Requirements ¶
Yii 1.1 or above)
Usage ¶
unzip the attached code under /protected/modules/
Add following code in config main.php under modules
'backup',
You can specify custom path for backup files.
'backup'=> array('path' => __DIR__.'/../_backup/' ),
Thats it , now you can open your web app with ?r=backup or /backup appended to home url.
where it's the menu
I install it in an empty project. I can see the "Manage database backup files" with an empty table bellow, no menu, action or anything.
When I browse to backup/default/create it did create the SQL file, witch is good, but probably I should have a button/link for this?
Also I don't see any security for it, I can see the page without being log-in, it's there any or can be added?
@rosoft2001
I had the same problem, and I changed the DefaultController layout to column2 to see the menu.
Regarding security, I found no access check neither
how to change the layout to see the menu?
I've tried
public function actionIndex()
{
$this->layout='//layouts/column2';
nothing changed? How you did it?
@rosoft2001
I did exactly the same thing:
class DefaultController extends Controller { public $layout='//layouts/column2'; // etc ....
Of course, you must have a column2 layout file located in protected/views/layouts, and this view must include a zii.widgets.CMenu using $this->menu to initialize 'items'.
I did nothing else ...
Solved
I have solved this in my 1.1 update.
Thanks,
Shiv
Just to say thank you.
Hey. I was looking for ideas to implement a backup system on my current project. Thanks for this extension.
sukunj
Very nice work...good extension....
Added modified date time
in controller actionIndex()
I added the following:
NOTE: I change my date format make sure create_time and modified_time are in the same date format.
....other data $columns['create_time'] = date( 'M-d-Y'.' \a\t '.' g:i A', filectime($path .$filename) ); if (date( 'M-d-Y'.' \a\t '.' g:i A', filemtime($path .$filename) ) > date( 'M-d-Y'.' \a\t '.' g:i A', filectime($path .$filename))) { $columns['modified_time'] = date( 'M-d-Y'.' \a\t '.' g:i A', filemtime($path .$filename) ); } else { $columns['modified_time'] = 'Never Modified'; } ..... other data
and in the index.php I added
'columns' => array( ...other columns 'modified_time', ...other columns
All it does it gets the last modified time from the file and displays it...
actionClean
I think it would be nice if on action clean it didn't wipe the main super user. I was playing around with it and I couldn't log back in so I had to restore a backup manually which defeats the whole purpose of cleaning it.
agree
Ya. Agree. I wish i do that soon.
recommend switching actionRestore
I really like this and have made tons of modification to your extension. Here is one that you might want to put on the next update.
It if the user selects a file from the list of backups it will restore that one.
If they use your button/menu link to restore a backup it will get the last .sql file uploaded file in the directory and restore that one (based on create time). If no .sql files exist then it will return no files exist.
Also, it does not redirect them to the update page it just displays a flash message in the index saying it was uploaded.
{ $path = $this->path; $files = glob($this->path."*.sql"); if ( isset($file)) { $sqlFile = $this->path . $file; $message = 'Succesfully restored database backup file: '.$file; $this->execSqlFile($sqlFile); Yii::app()->user->setFlash('success', $message); } if(!empty($files)){ $files = glob($this->path."*.sql"); array_multisort( array_map( 'filemtime', $files ), SORT_NUMERIC, SORT_DESC, $files ); $last_file = $files[0]; $sqlFile = $this->path . $last_file; $message = 'Succesfully restored database backup file: '.basename($last_file); $this->execSqlFile($sqlFile); Yii::app()->user->setFlash('success', $message); } else { $message = 'No files in directory'; Yii::app()->user->setFlash('error', $message); } $this->redirect(array('index')); }
index
//put this whereever you want the message to show //i use bootstrap thats why the div is called alert-success you can call it whatever you want or use an existing div with your styles. <?php if(Yii::app()->user->hasFlash('success')):?> <div class="alert-success" style="text-align: center; margin: 10px 0 10px 0; padding: 10px;"> <?php echo Yii::app()->user->getFlash('success'); ?> </div> <?php elseif(Yii::app()->user->hasFlash('error')):?> <div class="alert-error" style="text-align: center; margin: 10px 0 10px 0; padding: 10px;"> <?php echo Yii::app()->user->getFlash('error'); ?> </div> <?php endif; ?> //this will close the message if the user has js enabled after 4 seconds. if you changed the div name above change it in '$(".alert-success").... too <?php Yii::app()->clientScript->registerScript( 'HideAlert', '$(".alert-success, .alert-error").animate({opacity: 1.0}, 4000).fadeOut("slow");', CClientScript::POS_READY ); ?>
Thanks @skworden!
Thanks @skworden ,
I happy to hear that. I shall pick your changes for next release planned in next week.
Thanks,
Shiv
Table named "leave" causing error!
Hello, I have a table named "leave" which is causing an error since it is a reserved keyword! Have you cater for this plz? Anyone can help? Thanks!
PS: Error is as follows:
CDbCommand failed to execute the SQL statement: 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 'leave' at line 1. The SQL statement executed was: SHOW CREATE TABLE leave
backup
this extension is very useful for me to manged dabase
it save more time
thanks you.
@yiiihaaa
Thanks for reporting. I would fix that soon.
Thanks,
Shiv
@yiiihaaa
I have updated extension with fix for your problem. More changes are under testing and I shall release more features soon.
remote file disclosure
Hi.
The extension allows to download files from outside 'path' folder...
Example: http://myapp/backup/default/download?file=../config/main.php
Possible Fix:
public function actionDownload($file = null) { . . . $sqlFile = $this->path . basename($file); . . . }
@Gero
Thanks for reporting. I have fixed this bug.
Regards,
Shiv
Small inconsistency
Great extension!
I found a small inconsistency in the _list.php file.
The download and restore links are listed with lower case letters in the template, but is capitalized in the column definition. Therefor the links do not work.
Suggested change:
array( 'class' => 'CButtonColumn', 'template' => ' {download} {restore}', 'buttons'=>array ( 'download' => array ( 'url'=>'Yii::app()->createUrl("backup/default/download", array("file"=>$data["name"]))', ), 'restore' => array ( 'url'=>'Yii::app()->createUrl("backup/default/restore", array("file"=>$data["name"]))', ), 'delete' => array ( 'url'=>'Yii::app()->createUrl("backup/default/delete", array("file"=>$data["name"]))', ), ), ),
@trond
Thanks, I shall fix it in next release.
[SOLVED] (Problem with Nested Module) Cannot Delete, Download, & Restore Backup File
Everything was fine when I installed the module in /protected/modules/
but Delete, Download & Restore went wrong when I nested Module it.
How do I get around this? anyone? thanks.
*Edit[SOLVED]
To those of you encountering such problem, here's how I solved it.
goto: \protected\modules
Just modify the following
'url' => 'Yii::app()->createUrl("<module1>/<module1.1>/<controller>/<action>", array("file"=>$data["name"]))',
for example,
'url' => 'Yii::app()->createUrl("admin_m/backup/default/restore", array("file"=>$data["name"]))',
that's basically how I've solved my problem.
error :( use mssql :(
sp_create_table error use mssql, help me dude ....
SQLSTATE[42000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Could not find stored procedure 'sp_create_table'..
Error 500 Undefined index: Create Table
when I click on the create backup file it shows the error
Error 500 Undefined index: Create Table
but also create the file.
nice and greate extension but little problem Error 404 Unable to resolve the request "backup/site/index".
the link backup/site/index is working fine but when I click on another link i.e on my dashboard link it gives the error
Error 404 Unable to resolve the request "backup/site/index".
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.