v2.5.2
Giriş yap

ZipArshive hariç tutulaması gereken klasörleri hariç tutmuyor ?

acemi
167 defa görüntülendi

bir method oluşturdum fakat nerde hatam var bir türlü yakalayamadım.
root un zip yedeğini veya tar yediğini almaya çalışıyorum fakat method a hariç tutulacak klasörüleride veriyorum
ama bir türlü hariç tutulan klasörleri zip e veya tar a eklemesini engelleyemiyorum.

method ve kullanım şekli aşağıdaki gibidir.
teşekkürler.

    public function backupRoot($backupDir, $unwantedDirs = array(), $useZip = true) { 
        $backupName = 'backup-' . date('Y-m-d-H-i-s');
        $ext = ($useZip) ? '.zip' : '.tar.gz';
        $rootPath = realpath($_SERVER['DOCUMENT_ROOT']);
        $backupPath = $backupDir . '/' . $backupName . $ext;
        if ($useZip) {
            $zip = new \ZipArchive();
            $zip->open($backupPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
            $pathLen = strlen($rootPath) + 1;
            $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::SELF_FIRST);
            foreach ($iterator as $file) {
                // Dosya ismi "." veya ".." değilse
                if (!in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
                    $filePath = substr($file, $pathLen); 
                    $unwantedDirs = array_map('trim', $unwantedDirs); 
                    $filePath = trim(substr($file, $pathLen), '/'); 
                    if (!in_array($filePath, $unwantedDirs, true)) {
                        if (is_dir($file)) {
                            $zip->addEmptyDir($filePath);
                        } else {
                            $zip->addFile($file, $filePath);
                        }
                    }
                }
            }
            $zip->close();
        } else {
            $phar = new \PharData($backupPath);
            $pathLen = strlen($rootPath);
            $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::SELF_FIRST);
            foreach ($iterator as $file) {
                if (!in_array(substr($file, strrpos($file, '/') + 1), array('.', '..'))) {
                    $filePath = substr($file, $pathLen);
                    if (!in_array($filePath, $unwantedDirs)) {
                        if (is_dir($file)) {
                            $phar->addEmptyDir($filePath);
                        } else {
                            $phar->addFile($file, $filePath);
                        }
                    }
                }
            }
            $phar->compress(\Phar::GZ);
        }
        return $backupPath;
    }
    // Kullanırken
            $backupDir = $_SERVER["DOCUMENT_ROOT"];
            $unwantedDirs = array($backupDir."/public");
            $useZip = true; 
            $result = $Backup->backupRoot($backupDir, $unwantedDirs, $useZip);
Cevap yaz
Cevaplar (1)
acemi
348 gün önce

varmı yardım edebilecek biri ?