Welcome Guest, Not a member yet? Register   Sign In
Backup your source code with a single click!
#1

[eluser]spec[/eluser]
Create Backup.php
and paste following code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;

&lt;head&gt;
    &lt;meta http-equiv="Refresh" content="2; URL=http://localhost/proj" /&gt;
    &lt;meta name="author" content="" /&gt;

    &lt;title&gt;Backup&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;?php class Backup extends Controller {

    function __construct() {
        parent::Controller();
    }

    function index() {
        
        //DB backup:
        $this->load->dbutil();

        $backup = &$this->dbutil->backup();

        $this->load->helper('file');
        $date = strftime("%d-%b-%y at %Hh%M ");
        $db_backup_file = $date . 'db.gz';

        write_file('d:/htdocs/backup/proj/' . $db_backup_file, $backup);
        //<-DB backup
        
        //proj backup:
        $this->load->lib('zip');
        $path = '../proj/';

        $this->zip->read_dir($path);
        $date = strftime("%d-%b-%y at %Hh%M ");
        $proj_backup_file = $date . 'proj.zip';
        $this->zip->archive('d:/htdocs/backup/proj/' . $proj_backup_file); // Creates a file named myarchive.zip
        $data = 'Done. Redirecting in 2 sec<br>
        <strong>' . $db_backup_file . '</strong> - '.round((filesize('d:/htdocs/backup/proj/' . $db_backup_file)/1024),1).' KB <br>
        <strong>' . $proj_backup_file . '</strong> - '.round((filesize('d:/htdocs/backup/proj/'.$proj_backup_file)/1024),1).' KB <br>';
        
        $this->out->set_out($data);//display status info
        //<-proj backup
    }

} ?&gt;

&lt;/body&gt;
&lt;/html&gt;
Customize paths mentioned in the code and put Backup.php into controllers directory of your app.

You can then make a link to activate the controller, something like: <a href="http://localhost/proj/backup">Backup</a> and make backup of your current code with a sigle click!
#2

[eluser]huzzi[/eluser]
thanks for that, is there way to exclude certain directories?
#3

[eluser]spec[/eluser]
@haruzzi: yes, you should rewrite (or extend) system/libraries/Zip.php and exclude certain directories

take a look at function named read_dir and modify it, I would look at this part:
if (@is_dir($path.$file)){ $this->read_dir($path.$file."/", $preserve_filepath, $root_path); }




Theme © iAndrew 2016 - Forum software by © MyBB