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.
class Cron extends CI_Controller
public function backup()
//if you have previously connected to the FTP server make sure you have closed the connection
//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@example.com"), //email address(es) that the backup will be sent to
"email_from" => "firstname.lastname@example.org", //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
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-manager/overview
To make this run on a CRON job I used http://codeigniter.com/wiki/Cron_job_bootstrapper/
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.