I'm trying to create full site backup but i want to exclude a folder from archive.
My directory:
/application/
/backups/ >>> I dont want to archive this folder because of nested archiving.
/themes/
/uploads/
.htaccess
index.php
Tried following codes:
$this->load->library('zip');
$this->zip->read_dir(FCPATH);
$this->zip->archive(FCPATH.'backups/'.date('Y-m-d-His').'.zip');
You can workout something like this, in which you will never have to manually enter the new directory you create
$this->load->library('zip');
$data = array_diff(scandir(FCPATH), array('..', '.','backups'));
// 'backups' folder will be excluded here with '.' and '..'
foreach($data as $d) {
$path = FCPATH.$d;
if(is_dir($path))
$this->zip->read_dir($path, false);
if(is_file($path))
$this->zip->read_file($path, false);
}
$this->zip->archive(FCPATH.'backups/'.date('Y-m-d-His').'.zip');
My solution is a little manual that setting each root directories and files
like following:
$this->load->library('zip');
// Choose directory and files
$this->zip->read_dir(FCPATH.'application', false);
$this->zip->read_dir(FCPATH.'themes', false);
$this->zip->read_dir(FCPATH.'uploads', false);
$this->zip->read_file(FCPATH.'.htaccess', false);
$this->zip->read_file(FCPATH.'index.php', false);
$this->zip->archive(FCPATH.'backups/'.date('Y-m-d-His').'.zip');
Tested on CodeIgniter 3.x and Wamp Server
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.