Yii 1.1: backup

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

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.

Total 20 comments

#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.

*Edit[SOLVED]

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
@trond

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:

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"]))',
                    ),
                ),      
        ),
#12786 report it
shiv at 2013/04/12 03:26am
@Gero

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
@yiiihaaa

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
@yiiihaaa

Thanks for reporting. I would fix that soon.

Thanks, Shiv

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

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;
        $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
);
?>

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

Ya. Agree. I wish i do that soon.

#12105 report it
skworden at 2013/02/27 12:24pm
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.

#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
'modified_time',
...other columns

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

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

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
Solved

I have solved this in my 1.1 update.

Thanks, Shiv

#11326 report it
Raoul at 2013/01/06 09:49am
@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 ...

#11321 report it
rosoft2001 at 2013/01/05 05:33pm
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?

#11320 report it
Raoul at 2013/01/05 04:55pm
@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

Leave a comment

Please to leave your comment.

Create extension