Yii 1.1: backup

This module let you Backup / Restore / Clean database easily.

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.


Yii 1.1 or above)


unzip the attached code under /protected/modules/

Add following code in config main.php under modules


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.

Total 20 comments

#19701 report it
asifrafeeq at 2015/12/20 11:40am
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".
#19700 report it
asifrafeeq at 2015/12/20 11:38am
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.

#19092 report it
Tatasutiadi at 2015/03/13 12:17am
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'..

#16305 report it
JbalTero at 2014/02/08 03:13am
[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.


To those of you encountering such problem, here's how I solved it.

goto: \protected\modules\\<module1.1>\backup\views\default_list.php

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.

#15816 report it
shiv at 2013/12/19 07:43am

Thanks, I shall fix it in next release.

#15764 report it
trond at 2013/12/15 11:23am
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:

            'class' => 'CButtonColumn',
            'template' => ' {download} {restore}',
                    '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"]))',
#12786 report it
shiv at 2013/04/12 03:26am

Thanks for reporting. I have fixed this bug.

Regards, Shiv

#12775 report it
Gero at 2013/04/11 10:20am
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);
        . . .
#12761 report it
shiv at 2013/04/10 08:56am

I have updated extension with fix for your problem. More changes are under testing and I shall release more features soon.

#12715 report it
shiv at 2013/04/08 02:08am

Thanks for reporting. I would fix that soon.

Thanks, Shiv

#12387 report it
rajesh chaurasia at 2013/03/18 01:12am

this extension is very useful for me to manged dabase it save more time thanks you.

#12248 report it
yiiihaaa at 2013/03/09 03:12pm
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

#12216 report it
shiv at 2013/03/07 05:31am
Thanks @skworden!

Thanks @skworden ,

I happy to hear that. I shall pick your changes for next release planned in next week.

Thanks, Shiv

#12181 report it
skworden at 2013/03/04 03:30pm
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;
        Yii::app()->user->setFlash('success', $message);
                $files = glob($this->path."*.sql");
          array_map( 'filemtime', $files ),
        $last_file = $files[0];
        $sqlFile = $this->path . $last_file;
        $message = 'Succesfully restored database backup file:  '.basename($last_file);
        Yii::app()->user->setFlash('success', $message);
        else {  
        $message = 'No files in directory';
        Yii::app()->user->setFlash('error', $message);


//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'); ?>
<?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'); ?>
<?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
   '$(".alert-success, .alert-error").animate({opacity: 1.0}, 4000).fadeOut("slow");',

#12111 report it
shiv at 2013/02/27 02:59pm

Ya. Agree. I wish i do that soon.

#12105 report it
skworden at 2013/02/27 12:24pm

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.

#12085 report it
skworden at 2013/02/26 03:06pm
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
...other columns

All it does it gets the last modified time from the file and displays it...

#11364 report it
Sukunj Mendpara at 2013/01/09 06:55am

Very nice work...good extension....

#11335 report it
thiagovidal at 2013/01/06 07:38pm
Just to say thank you.

Hey. I was looking for ideas to implement a backup system on my current project. Thanks for this extension.

#11328 report it
shiv at 2013/01/06 12:16pm

I have solved this in my 1.1 update.

Thanks, Shiv

Leave a comment

Please to leave your comment.

Create extension