Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[BackupTools] - Human readable archive
10-26-2010, 05:13 PM,
#1
[BackupTools] - Human readable archive
Hello

There is a problem with "Human readable archive". TAR accept only filename with 100 characters.

Then i'm modified code to create a ZIP file.
This function can be used for classic backup (not tested)

In the file "op.CreateFolderArchive.php"
Add this function
PHP Code:
function createFolderZIP($folder$zip)
{
    global 
$settings,$human_readable;

    
$documents=$folder->getDocuments();
    foreach (
$documents as $document){
        
        if (
file_exists($settings->_contentDir.$document->getDir())){

            if (
$human_readable){
            
                
// create an archive containing the files with original names and DMS path 
                // thanks to Doudoux 

                
$latestContent $document->getLatestContent();
                if (
is_object($latestContent))
                {
                    
$zip->addFile(
                      
$settings->_contentDir.$latestContent->getDir().$latestContent->getVersion().$latestContent->getFileType(),
                      
getFolderPathPlainAST($folder)."/".$document->getID()."_".mydmsDecodeString($latestContent->getOriginalFileName()));
                }
            
            }else{

                
// create a server backup archive

                
$handle opendir($settings->_contentDir.$document->getDir());
                while (
$entry readdir($handle) )
                {
                    if (!
is_dir($settings->_contentDir.$document->getDir().$entry)){

                      
$zip->addFile($settings->_contentDir.$document->getDir().$entry,$document->getDir().$entry);
                    }

                }
                
closedir($handle);
            }
        }    
    }

    
$subFolders=$folder->getSubfolders();
    foreach (
$subFolders as $folder)
        if (!
createFolderZIP($folder$zip))
            return 
false;
    
    return 
true;




Change
PHP Code:
if ($human_readable)$ark_name $settings->_contentDir.time()."_".$folderid."_HR.tar";
else 
$ark_name $settings->_contentDir.time()."_".$folderid.".tar";

$ark fopen($ark_name,"w");

if (!
createFolderTar($folder,$ark)) {
    
fclose($ark);
    
unlink($ark_name);
    
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
}

TarAddFooter($ark);
fclose($ark);

if (
gzcompressfile($ark_name,9)) unlink($ark_name);
else 
UI::exitError(getMLText("admin_tools"),getMLText("error_occured")); 

To

PHP Code:
if ($human_readable)
{
    
$ark_name $settings->_contentDir.time()."_".$folderid."_HR.zip";
    
    
$zip = new ZipArchive;
    if (
$zip->open($ark_nameZIPARCHIVE::CREATE) === TRUE)
    {
      if (!
createFolderZIP($folder$zip))
      {
        
$zip->close();
        
unlink($ark_name);
        
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
      }
      
      
$zip->close();
    }
}
else
{
    
$ark_name $settings->_contentDir.time()."_".$folderid.".tar";

    
$ark fopen($ark_name,"w");

    if (!
createFolderTar($folder,$ark)) {
        
fclose($ark);
        
unlink($ark_name);
        
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));
    }

    
TarAddFooter($ark);
    
fclose($ark);
    
    if (
gzcompressfile($ark_name,9)) 
        
unlink($ark_name);
    else 
        
UI::exitError(getMLText("admin_tools"),getMLText("error_occured"));    


BUG with caracters:
PHP Code:
function getFolderPathPlainAST($folder) {
    
$path="";
    
$folderPath $folder->getPath();
    for (
$i 0$i  count($folderPath); $i++) {
        
//$path .= $folderPath[$i]->getName();       
        
$path .= mydmsDecodeString($folderPath[$i]->getName());
        if (
$i+count($folderPath)) $path .= "/";
    }
    return 
$path;


In the file "out.BackupTools.php"
PHP Code:
while ($e readdir($handle)){
    if (
is_dir($settings->_contentDir.$e)) continue;
    if (
strpos($e,".tar.gz")==FALSE)
        continue;
    
$entries[] = $e;

to
PHP Code:
while ($e readdir($handle)){
    if (
is_dir($settings->_contentDir.$e)) continue;
    if ((
strpos($e,".tar.gz")==FALSE) && (strpos($e,".zip")==FALSE))
        continue;
    
$entries[] = $e;


There is a problem, accented characters in the ZIP file

Doudoux


Attached Files
.php   op.CreateFolderArchive.php (Size: 8.05 KB / Downloads: 3)
.php   out.BackupTools.php (Size: 6.16 KB / Downloads: 1)
Reply
10-26-2010, 09:37 PM,
#2
RE: [BackupTools] - Human readable archive
Thank you for the fix.
Do you know if zip archive creation will work on every system?
Does it depends on some version-specific library?
Reply
10-27-2010, 04:11 PM,
#3
RE: [BackupTools] - Human readable archive
(10-26-2010, 09:37 PM)matteo lucarelli Wrote: Do you know if zip archive creation will work on every system?
No, i use WAMP.
I would try to do a test on linux.

(10-26-2010, 09:37 PM)matteo lucarelli Wrote: Does it depends on some version-specific library?
i use php_zip module

Reply
10-29-2010, 03:39 PM,
#4
RE: [BackupTools] - Human readable archive
Well, what should be done to assure the wide compatibility of letoDMS with your patch?
Reply
11-05-2010, 10:51 PM,
#5
RE: [BackupTools] - Human readable archive
I'm testing on linux. It's OK with a simple test.

My config : ubuntu 9.10 / apache 2 / Mysql 5.1
(see attachment file)


Attached Files
.html   info.php.html (Size: 50.17 KB / Downloads: 1)
Reply
03-27-2011, 03:09 AM,
#6
RE: [BackupTools] - Human readable archive
Up for the next release Wink
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)

Contact Us | LetoDMS Community Forum | Return to Top | | Lite (Archive) Mode | RSS Syndication