Welcome Guest, Not a member yet? Register   Sign In
Site Backup Manager
#1

[eluser]mic[/eluser]
Site Backup Manager
Version 1.2 - Beta

REQUIRES PHP 5+ & CodeIgniter 2.0+

Create backups of the mysql DB, requires that the mysql driver be used not the mysqli

Backups are created daily, weekly and monthly from the day they are first run. Old backups will be removed after the pre-defined amount of prior backups has completed first.

Options to send files via FTP to external server and/or email to one or more email addresses.

Backup all or selected files from the site. These will be in the same zip file as the sql backup.

Example Controller
cron.php
Code:
class Cron extends CI_Controller
{
  
public function backup()
{
  
  //if you have previously connected to the FTP server make sure you have closed the connection
  //$this->ftp->close();  
  
  //the backup library requires that you have already connected to your database
  
  $prefs = array(
      "base_path"   => "D:/xampp/htdocs/backup_library_1.2/", //the base path on your server when the file are located
      "backup_dir"  => "backups", //the folder that you will use on this server to hold the backup files
      "ignore_table"  => array(), //ignores tables in the database you are connected to
      "backup_tables"  => array(), //backs up only these tables in the database you are connected to
      "ftp_transfer"  => false, //true = attempts to connect to the FTP server to transfer your backup files, false = stores files locally only
      "ftp_server"  => "ftp.domain.com", //the ftp URL
      "ftp_user"   => "ftp_user", //the ftp username
      "ftp_pass"   => "ftp_pass", //the ftp password
      "ftp_base_path"  => "", //if your site is located in a public_html folder or other like this. No /(slash) required
      "ftp_port"   => 21, //the ftp port number
      "remote_dir"  => "remote_folder", //the folder on the remote server where the FTP will place files this can be a directory like `home/domain/folder`
      "send_email"  => false, //true = sends backup files to the email address if it is able to, false = doesn't attempt an email
      "email_addresses" => array("[email protected]"), //email address(es) that the backup will be sent to
      "email_from"  => "[email protected]", //the email address that the backup email will be from
      "email_from_name" => "Backup Script", //the name that the backup email will be from
      "max_mail_size"  => 0, //the max size in bytes that the email account can receive
      "file_backup"  => true, //true = backup the site files, false = just the databases
      "directories"   => array(), //empty array backups everything or you can list directories to backup array("application", "forum", "resources/uploads")
      "copy_directory" => "site_files" //this is the temp directory that is used when creating a backup of the site files
  );
    
  $this->load->library("backup");  
  
  $this->backup->init($prefs);
  $this->backup->run();
  
}

}

(2011-10-06)
Minor Bug Fixes

1.1 to 1.2 (2011-09-20)
File backup was unable to back the entire site, this has now been changed and providing an empty $directories array will backup all files located in the site.
The temp directory is removed once the script has finished with it backing up all the files.

1.0 to 1.1 (2011-07-13)
File backup was added to allow the site files to be backed up in the same zip file
Options were added to allow files back ups or not.

If anyone has any ideas or suggestions of how I can imrpove this please let me know.

Can be downloaded at https://bitbucket.org/mic2100/ci-backup-...r/overview

To make this run on a CRON job I used http://codeigniter.com/wiki/Cron_job_bootstrapper/

KNOWN BUGS:

Sometimes with large files when sending via FTP or email the script can run on forever. The files are getting sent, the script is just not ending. I am unsure whether this is a CI bug or something else that I have done. To get around this I setup a timeout on the CRON.
#2

[eluser]rip_pit[/eluser]
i'm looking for such app, is it still active and maintened ?

i noticed the download link from github include the whole CI app, including system files etc that are out of date, so i publish the only files needed for the backup to work :

\application\config\email.php
\application\controllers\cron.php
\application\hooks\compress.php
\application\libraries\backup.php

1. configurate email and cron.
2. execute http://yoursite/cron/backup

localy without ftp transfer nor email sending : works perfect ! thanx !!
#3

[eluser]rip_pit[/eluser]
so i tested it online (live) and it works like a charm !

here are some mods that i used to customise that might be helpfull to someone :
* Get the top root path (get /public/ instead of /public/www/ ) where to store the backup
* require a password to execute
* reuse already set config values for dbname, paths, etc.

controllers/cron.php including the mods :
Code:
class Cron extends CI_Controller
{

  /**
   * error message if unauthorized
   * @var str
   */
  var $err_message = "unauthorized access.";

  /**
   *
   */
  function index() {
    show_error($this->err_message,'401');
  }

  
  /**
   * auto backup auto
   *
   * @param str $userpwd, include the pass in the 1st segment of url. should match with the password value into $required_url_password
   * Eg. website.com/cron/backup/YourPassword
   */
public function backup($userpwd=null)
{

    // require passw in url to autorize execution
    $required_url_password = 'YourPassword';
    if ( !isset($userpwd) || !$userpwd || $userpwd !== $required_url_password )
      show_error($this->err_message,'401');


  //if you have previously connected to the FTP server make sure you have closed the connection
  //$this->ftp->close();  

    // format path to have a real path, and not a path ending with /../
    $base_path = realpath(BASEPATH."../") . '/';
    //get the top root path

    //the backup library requires that you have already connected to your database

    $prefs = array( "base_path"   => $base_path,
      //etc. set the rest of the config
      "backup_dir"  => "backups", //the folder that you will use on this server to hold the backup files
      /* Set this for multiple databases and comment out the ignore_table and backup_tables elements */
      "backup_information" =>  array(
              array( "database"     => $this->db->database,
                "active_group"  => 'default', //set in the config/database.php
                "ignore_table" => array(), //containts a list of all the tables to ignore, leave empty to backup all
                "backup_tables" => array() //contains a list of all the tables that need backing up, leave empty to backup all
              )
             ),
      /* or set these and leave the backup_information commented out */
      #"ignore_table"  => array(), //ignores tables in the database you are connected to
      #"backup_tables" => array(), //backs up only these tables in the database you are connected to
        
      "ftp_transfer"  => false, //true = attempts to connect to the FTP server to transfer your backup files, false = stores files locally only
      "ftp_server"  => "ftp.domain.com", //the ftp URL
      "ftp_user"   => "ftp_user", //the ftp username
      "ftp_pass"   => "ftp_pass", //the ftp password
      "ftp_base_path"  => "", //if your site is located in a public_html folder or other like this. No /(slash) required
      "ftp_port"   => 21, //the ftp port number
      "remote_dir"  => "remote_folder", //the folder on the remote server where the FTP will place files this can be a directory like `home/domain/folder`
        
      "send_email"  => false, //true = sends backup files to the email address if it is able to, false = doesn't attempt an email
      "email_addresses" => array(config_item('admin_email')), //email address(es) that the backup will be sent to
      "email_from"  => config_item('admin_email'), //the email address that the backup email will be from
      "email_from_name" => "Backup Script", //the name that the backup email will be from
      "max_mail_size"  => 0, //the max size in bytes that the email account can receive

      "file_backup"  => true, //true = backup the site files, false = just the databases
      "directories"   => array(), //empty array backups everything or you can list directories to backup array("application", "forum", "resources/uploads")
      "copy_directory" => "backup_files_temp" //this is the temp directory that is used when creating a backup of the site files);


                $this->load->library("backup");
  
  $this->backup->init($prefs);
  $this->backup->run();
  
}

}
#4

[eluser]mic[/eluser]
Thanks for the feedback rip_pit, I had given up following this thread after no one responded for over 1 year. I'm so glad that it worked for you Smile

I had thought about making some of the changes as per your changes, but I have just not had the time to implement them!
#5

[eluser]rip_pit[/eluser]
thanx again and happy new year Smile
#6

[eluser]Pedroshow[/eluser]
You should integrate others services, like amazon s3
#7

[eluser]anhsk.ohbo[/eluser]
perfect! i don't look thank button @@ thank u Big Grin
#8

[eluser]quickshiftin[/eluser]
Very nice!




Theme © iAndrew 2016 - Forum software by © MyBB