php - How can I exclude folders with this backup script? -
i'm using great script backup folders on server, there couple of folders want exclude backup. how go excluding them?
thanks
<?php /* * php: recursively backup files & folders zip-file * (c) 2012-2014: marvin menzerath - http://menzerath.eu * contribution: drew toddsby */ // make sure script can handle large folders/files ini_set('max_execution_time', 600); ini_set('memory_limit','1024m'); // start backup! zipdata('/var/www/html/uploaded', '/var/www/html/uploaded.zip'); echo 'finished.'; // here magic happens :) function zipdata($source, $destination) { if (extension_loaded('zip')) { if (file_exists($source)) { $zip = new ziparchive(); if ($zip->open($destination, ziparchive::create)) { $source = realpath($source); if (is_dir($source)) { $iterator = new recursivedirectoryiterator($source); // skip dot files while iterating $iterator->setflags(recursivedirectoryiterator::skip_dots); $files = new recursiveiteratoriterator($iterator, recursiveiteratoriterator::self_first); foreach ($files $file) { $file = realpath($file); if (is_dir($file)) { $zip->addemptydir(str_replace($source . '/', '', $file . '/')); } else if (is_file($file)) { $zip->addfromstring(str_replace($source . '/', '', $file), file_get_contents($file)); } } } else if (is_file($source)) { $zip->addfromstring(basename($source), file_get_contents($source)); } } return $zip->close(); } } return false; }
put in $no_zip
path want exclude. , see line if(!in_array($file, $no_zip) {
<?php /* * php: recursively backup files & folders zip-file * (c) 2012-2014: marvin menzerath - http://menzerath.eu * contribution: drew toddsby */ // make sure script can handle large folders/files ini_set('max_execution_time', 600); ini_set('memory_limit','1024m'); // start backup! zipdata('/var/www/html/uploaded', '/var/www/html/uploaded.zip'); echo 'finished.'; $no_zip = array('path_1', 'path_2'); // here magic happens :) edit: funny ;-) function zipdata($source, $destination) { if (extension_loaded('zip')) { if (file_exists($source)) { $zip = new ziparchive(); if ($zip->open($destination, ziparchive::create)) { $source = realpath($source); if (is_dir($source)) { $iterator = new recursivedirectoryiterator($source); // skip dot files while iterating $iterator->setflags(recursivedirectoryiterator::skip_dots); $files = new recursiveiteratoriterator($iterator, recursiveiteratoriterator::self_first); foreach ($files $file) { //check if(!in_array($file, $no_zip)) { $file = realpath($file); if (is_dir($file)) { $zip->addemptydir(str_replace($source . '/', '', $file . '/')); } else if (is_file($file)) { $zip->addfromstring(str_replace($source . '/', '', $file), file_get_contents($file)); } } } } else if (is_file($source)) { $zip->addfromstring(basename($source), file_get_contents($source)); } } return $zip->close(); } } return false; }
Comments
Post a Comment