From: Rene R. <ren...@us...> - 2002-10-29 03:15:48
|
Update of /cvsroot/bobs/bobs/inc In directory usw-pr-cvs1:/tmp/cvs-serv14737/inc Modified Files: class_backup.php class_files.php class_restore.php class_tree.php Log Message: Rather large patch: More templates added, so we are almost only using templates now. class_backup partly cleaned up. Still needs more work. I removed the .raw file lists and use only php now. Index: class_backup.php =================================================================== RCS file: /cvsroot/bobs/bobs/inc/class_backup.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** class_backup.php 1 Sep 2002 02:24:21 -0000 1.4 --- class_backup.php 29 Oct 2002 03:15:41 -0000 1.5 *************** *** 4,26 **** description: backup functions - server - server_backup ($server, $share) - server_increment ($server, $share) - server_create_lists ($server, $share, $folders) - server_progress ($server, $share) - server_check_in_progress () - - directory - dir_check ($server, $share, $folder) - */ - class backup { var $siteroot = ''; // root of the http site ! var $server = ''; // the servers name var $server_ip = ''; // the server ip address var $backupdir = ''; // base dir to do full current backups --- 4,15 ---- description: backup functions */ class backup { var $siteroot = ''; // root of the http site ! var $server = ''; // the servers name var $server_ip = ''; // the server ip address var $backupdir = ''; // base dir to do full current backups *************** *** 28,43 **** var $incrementdir = ''; // base dir to store increment backups var $processdir = ''; // base for for store processes and sessions ! var $share = ''; // what share to backup (rsync share that is) var $nfs_share = ''; // the share's nfs mount point ! var $files = ''; // files to do stuff with var $folders = ''; // folders to do stuff with ! var $size = ''; // size to search for ! var $current_folder = ''; // folder store var $command = ''; // shell command store var $session_id = ''; // unique session id var $filelinks = ''; // files that are linked (depend on each other) - - - // new settings var $rsync_share = ''; // name of the rsync share var $smb_share = ''; // name of the smb share --- 17,29 ---- var $incrementdir = ''; // base dir to store increment backups var $processdir = ''; // base for for store processes and sessions ! var $share = ''; // descriptive name for the share to backup var $nfs_share = ''; // the share's nfs mount point ! var $files = ''; // files to do stuff with var $folders = ''; // folders to do stuff with ! var $size = ''; // size to search for ! var $current_folder = ''; // folder store var $command = ''; // shell command store var $session_id = ''; // unique session id var $filelinks = ''; // files that are linked (depend on each other) var $rsync_share = ''; // name of the rsync share var $smb_share = ''; // name of the smb share *************** *** 45,49 **** var $restore_method = ''; // restore method (smb/nfs) var $password = ''; // cleartext password (for smb mounts) ! var $login = ''; // login name (for smb mounts) --- 31,38 ---- var $restore_method = ''; // restore method (smb/nfs) var $password = ''; // cleartext password (for smb mounts) ! var $login = ''; // login name (for smb mounts) ! var $magic0 = '__///__0'; // what to use as magic text (you must be sure that no directories use this name) ! var $magic1 = '__///__1'; // what to use as magic text (you must be sure that no directories use this name) ! *************** *** 66,70 **** $this->server_ip = $vol_conf["server_ip"]; - // new settings $this->smb_share = $vol_conf["smb_share"]; $this->backup_method = $vol_conf["backup_method"]; --- 55,58 ---- *************** *** 83,87 **** $this->session_id = rand(); ! // NOTE: It might be a good idea to place a command in the queue to delete sessions older than a week. // This would be a nice place to call it since it is not an intensive task. // $this->clean_old_sessions(); --- 71,75 ---- $this->session_id = rand(); ! // FIXME: It might be a good idea to place a command in the queue to delete sessions older than a week. // This would be a nice place to call it since it is not an intensive task. // $this->clean_old_sessions(); *************** *** 109,112 **** --- 97,102 ---- $result["curdir_db"] = $this->backupdir . '/' . $this->server . '/' . $this->share . '.dirindex.db'; + $result["magic0"] = $this->magic0; + $result["magic1"] = $this->magic1; $result["processdir"] = $this->processdir; $result["session_id"] = $this->session_id; *************** *** 119,123 **** $result["filelinks"] = $this->filelinks; - // new options $result["smb_share"] = $this->smb_share; $result["password"] = $this->password; --- 109,112 ---- *************** *** 183,190 **** // put together the script we need to execute $backupcommand = 'rsync -e ssh --archive --verbose --delete --backup ' ; - - // enable this to run with without touching any files (except the $share.log) - //$backupcommand .= ' --dry-run '; - $backupcommand .= $exclude_from; $backupcommand .= '--backup-dir="' . $this->incomingdir . '/' . $this->server . '/' . $this->share . '/"' ; --- 172,175 ---- *************** *** 197,207 **** } ! $backupcommand .= '::' . $this->share . ' "' . $this->backupdir . '/' . $this->server . '/' . $this->share . '/"'; ! // $backupcommand .= ' > "' . $this->backupdir . '/' . $this->server . '/' . $this->share . '/rsync.log" '; $shell = "#!/bin/sh\n"; $shell .= "# Description: Backup files from server\n"; $shell .= $backupcommand . "\n"; - // $shell .= 'chown -R apache:apache "' . $this->incomingdir . '/' . $this->server . '/' . $this->share . '/"' . "\n"; --- 182,190 ---- } ! $backupcommand .= '::' . $this->rsync_share . ' "' . $this->backupdir . '/' . $this->server . '/' . $this->share . '/"'; $shell = "#!/bin/sh\n"; $shell .= "# Description: Backup files from server\n"; $shell .= $backupcommand . "\n"; *************** *** 225,268 **** ! // shell 1: mount the share ! // check for read access ! $shell = "#!/bin/bash\n"; ! $shell .= "# Description: Backup files from server\n"; ! // create the mount point ! $shell .= 'mkdir -p "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\"\n"; ! $shell .= 'if [ -d "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . '" ]' . "\n"; ! $shell .= 'then'. "\n"; ! // check if the server can be mounted ! $shell .= 'mount -t smbfs -o username=' . $this->login . ',password=' . $this->password . ' '; ! if ( $this->server_ip == '' ) { ! $shell .= '//' . $this->server . '/' . $this->smb_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\n"; ! } else { ! $shell .= '//' . $this->server_ip . '/' . $this->smb_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\n"; ! } ! $shell .= 'if [ $? -eq 0 ]' . "\n"; ! $shell .= 'then'. "\n"; ! // create a lock file if succesful ! $shell .= 'touch "' . $this->processdir . '/session/' . $this->session_id . ".backup.servmount.lock\"\n"; ! $shell .= 'exit' . "\n"; ! $shell .= 'fi' . "\n"; ! $shell .= 'fi' . "\n"; // add the script to command queue $this->command = $shell ; $this->add_queue_command($shell, "bash"); ! ! // shell 2: ! // check lock file ! // rsync if true ! // exit if false ! $shell = "#!/bin/bash\n"; ! $shell .= 'if [ -e "' . $this->processdir . '/session/' . $this->session_id . '.backup.servmount.lock" ]' . "\n"; ! $shell .= 'then'. "\n"; ! $shell .= 'rsync --archive --delete --backup --backup-dir="' . $this->incomingdir . '/' . $this->server . '/' . $this->share . '" '; ! $shell .= ' "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . '/" "' . $this->backupdir . '/' . $this->server . '/' . $this->share . '/"' . "\n"; ! $shell .= 'exit' . "\n"; ! $shell .= 'fi' . "\n"; // add the script to command queue --- 208,257 ---- ! // variable needed by more than one script ! $shstats = $this->processdir . "/shstats"; ! $lockfile = $this->processdir . '/session/' . $this->session_id . ".backup.servmount.lock"; ! $mountdir = $this->processdir . '/mounts/' . $this->server . '/' . $this->share; ! // shell 1: mount the share ! // check for read access ! ! // prepare the variable we need to fill out ! $mnt_command = 'mount -t smbfs -o username=' . $this->login . ',password=' . $this->password . ' '; ! if ( $this->server_ip == '' ) { ! $mnt_command .= '//' . $this->server . '/' . $this->smb_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share; ! } else { ! $mnt_command .= '//' . $this->server_ip . '/' . $this->smb_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share; ! } ! ! $t = new rFastTemplate('.'); ! $t->define (array('content' => '../inc/templates/backup_smb_mount_server.sh')); ! $t->assign ('MOUNTDIR', $mountdir); ! $t->assign ('MOUNT_CMD', $mnt_command); ! $t->assign ('SESSION_ID', $this->session_id); ! $t->assign ('SHSTATS', $shstats); ! $t->assign ('LOCKFILE', $lockfile); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); // add the script to command queue $this->command = $shell ; $this->add_queue_command($shell, "bash"); ! ! // shell 2: ! // check lock file ! // rsync if true ! // exit if false ! $backup_cmd = 'rsync --archive --delete --backup --backup-dir="' . $this->incomingdir . '/' . $this->server . '/' . $this->share . '" '; ! $backup_cmd .= ' "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . '/" "' . $this->backupdir . '/' . $this->server . '/' . $this->share . '/"'; ! ! $t->define (array('content' => '../inc/templates/backup_smb_backup_files.sh')); ! $t->assign ('MOUNTDIR', $mountdir); ! $t->assign ('BACKUP_CMD', $backup_cmd); ! $t->assign ('SESSION_ID', $this->session_id); ! $t->assign ('SHSTATS', $shstats); ! $t->assign ('LOCKFILE', $lockfile); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); // add the script to command queue *************** *** 270,285 **** $this->add_queue_command($shell, "bash"); ! // shell 3: ! // check smb_status ! // umount if true and delete smb_status ! // if false delete lock file and report error to bobs.log ! $shell = "#!/bin/bash\n"; ! $shell .= 'if [ -a "' . $this->processdir . '/session/' . $this->session_id . '.backup.servmount.lock" ]' . "\n"; ! $shell .= 'then'. "\n"; ! $shell .= 'umount "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\"\n"; ! $shell .= 'rm -f "' . $this->processdir . '/session/' . $this->session_id . ".backup.servmount.lock\"\n"; ! $shell .= 'exit' . "\n"; ! $shell .= 'fi' . "\n"; // add the script to command queue --- 259,273 ---- $this->add_queue_command($shell, "bash"); ! // shell 3: ! // check smb_status ! // umount if true and delete smb_status ! // if false delete lock file and report error to bobs.log ! ! $t->define (array('content' => '../inc/templates/backup_smb_unmount_server.sh')); ! $t->assign ('MOUNTDIR', $mountdir); ! $t->assign ('LOCKFILE', $lockfile); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); // add the script to command queue *************** *** 299,341 **** // 3. umount the NFS share again (if mounted in the first place) - // shell 1: mount the share - // check for read access ! $shell = "#!/bin/bash\n"; ! $shell .= "# Description: Backup files from server\n"; ! // create the mount point ! $shell .= 'mkdir -p "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\"\n"; ! $shell .= 'if [ -d "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . '" ]' . "\n"; ! $shell .= 'then'. "\n"; ! // check if the server can be mounted ! $shell .= 'mount -t nfs '; ! if ( $this->server_ip == '' ) { ! $shell .= $this->server . ':' . $this->nfs_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\n"; ! } else { ! $shell .= $this->server_ip . ':' . $this->nfs_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\n"; ! } ! $shell .= 'if [ $? -eq 0 ]' . "\n"; ! $shell .= 'then'. "\n"; ! $shell .= 'touch "' . $this->processdir . '/session/' . $this->session_id . ".backup.servmount.lock\"\n"; ! $shell .= 'exit' . "\n"; ! $shell .= 'fi' . "\n"; ! $shell .= 'fi' . "\n"; // add the script to command queue $this->command = $shell ; $this->add_queue_command($shell, "bash"); ! // shell 2: ! // check smb_status ! // rsync if true ! // exit if false ! $shell = "#!/bin/bash\n"; ! $shell .= 'if [ -e "' . $this->processdir . '/session/' . $this->session_id . '.backup.servmount.lock" ]' . "\n"; ! $shell .= 'then'. "\n"; ! $shell .= 'rsync --archive --delete --backup --backup-dir="' . $this->incomingdir . '/' . $this->server . '/' . $this->share . '" '; ! $shell .= ' "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . '/" "' . $this->backupdir . '/' . $this->server . '/' . $this->share . '/"' . "\n"; ! $shell .= 'exit' . "\n"; ! $shell .= 'fi' . "\n"; // add the script to command queue --- 287,340 ---- // 3. umount the NFS share again (if mounted in the first place) ! // variable needed by more than one script ! $shstats = $this->processdir . "/shstats"; ! $lockfile = $this->processdir . '/session/' . $this->session_id . ".backup.servmount.lock"; ! $mountdir = $this->processdir . '/mounts/' . $this->server . '/' . $this->share; ! ! ! // shell 1: mount the share ! // check for read access ! ! // check if the server can be mounted ! $mnt_command = 'mount -t nfs '; ! if ( $this->server_ip == '' ) { ! $mnt_command .= $this->server . ':' . $this->nfs_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\n"; ! } else { ! $mnt_command .= $this->server_ip . ':' . $this->nfs_share . ' ' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\n"; ! } ! ! $t = new rFastTemplate('.'); ! $t->define (array('content' => '../inc/templates/backup_nfs_mount_server.sh')); ! $t->assign ('MOUNTDIR', $mountdir); ! $t->assign ('MOUNT_CMD', $mnt_command); ! $t->assign ('SESSION_ID', $this->session_id); ! $t->assign ('SHSTATS', $shstats); ! $t->assign ('LOCKFILE', $lockfile); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); // add the script to command queue $this->command = $shell ; $this->add_queue_command($shell, "bash"); + + ! // shell 2: ! // check nfs_status ! // rsync if true ! // exit if false ! $backup_cmd = 'rsync --archive --delete --backup --backup-dir="' . $this->incomingdir . '/' . $this->server . '/' . $this->share . '" '; ! $backup_cmd .= ' "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . '/" "' . $this->backupdir . '/' . $this->server . '/' . $this->share . '/"' . "\n"; ! ! $t->define (array('content' => '../inc/templates/backup_nfs_backup_files.sh')); ! $t->assign ('MOUNTDIR', $mountdir); ! $t->assign ('BACKUP_CMD', $backup_cmd); ! $t->assign ('SESSION_ID', $this->session_id); ! $t->assign ('SHSTATS', $shstats); ! $t->assign ('LOCKFILE', $lockfile); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); // add the script to command queue *************** *** 343,358 **** $this->add_queue_command($shell, "bash"); ! // shell 3: ! // check lock file ! // umount if true and delete lock file ! // if false delete lock file and report error to bobs.log ! $shell = "#!/bin/bash\n"; ! $shell .= 'if [ -a "' . $this->processdir . '/session/' . $this->session_id . '.backup.servmount.lock" ]' . "\n"; ! $shell .= 'then'. "\n"; ! $shell .= 'umount "' . $this->processdir . '/mounts/' . $this->server . '/' . $this->share . "\"\n"; ! $shell .= 'rm -f "' . $this->processdir . '/session/' . $this->session_id . ".backup.servmount.lock\"\n"; ! $shell .= 'exit' . "\n"; ! $shell .= 'fi' . "\n"; // add the script to command queue --- 342,356 ---- $this->add_queue_command($shell, "bash"); ! // shell 3: ! // check lock file ! // umount if true and delete lock file ! // if false delete lock file and report error to bobs.log ! ! $t->define (array('content' => '../inc/templates/backup_smb_unmount_server.sh')); ! $t->assign ('MOUNTDIR', $mountdir); ! $t->assign ('LOCKFILE', $lockfile); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); // add the script to command queue *************** *** 374,435 **** $escape = "\ \\\*\+\[\]\^\$\(\)\{\}\=\!\<\>\|\:\#"; ! $shell = "#!/bin/bash\n"; ! $shell .= "# increment files in incoming\n"; ! $shell .= 'SRCDIR="' . $this->incomingdir . '/"' . "\n"; ! $shell .= 'DSTDIR="' . $this->incrementdir . '/"' . "\n"; ! // get the date in .YYYY.DDD format $date = sprintf(".%04d.%03d", date("Y"), date("z")); ! $shell .= 'DATE="' . $date . "\"\n"; ! ! //# find should output x lines with: ! //# 1: the name of the file ! //# 2: the name of the file the dir relative to the SRCDIR ! ! $tmpfile = $this->processdir . '/session/' . $this->session_id . ".incrementlist"; ! $shell .= "# clear the filelist if it exists\n"; ! $shell .= 'rm -f "' . $tmpfile . "\"\n"; ! $shell .= 'find "$SRCDIR" -type f -printf "%f\n%P\n" >> "' . $tmpfile . "\"\n"; ! ! // write and end_of_file identifier ! $shell .= 'echo "END_OF_FILE_LIST_ZXC" >> "' . $tmpfile . "\"\n"; ! $shell .= 'echo "END_OF_FILE_LIST_ZXC" >> "' . $tmpfile . "\"\n"; ! $shell .= 'filelist="' . $tmpfile . "\"\n"; ! ! $shell .= 'move () {' . "\n"; ! $shell .= ' if [ -d "$DSTDIR$RELDIR" ]' . "\n"; ! $shell .= ' then' . "\n"; ! $shell .= ' `mv "$SRCDIR$RELDIR$NAME" "$DSTDIR$RELDIR$NAME$DATE"`' . "\n"; ! $shell .= ' else' . "\n"; ! //# create dst dir if it doesn't exist ! $shell .= ' `mkdir --parents "$DSTDIR$RELDIR"`' . "\n"; ! $shell .= ' `mv "$SRCDIR$RELDIR$NAME" "$DSTDIR$RELDIR$NAME$DATE"`' . "\n"; ! $shell .= ' fi' . "\n"; ! $shell .= '}' . "\n"; ! $shell .= 'count=0' . "\n"; ! $shell .= 'while [ "$NAME" != "END_OF_FILE_LIST_ZXC" ]' . "\n"; ! $shell .= ' do' . "\n"; ! $shell .= ' read NAME' . "\n"; ! $shell .= ' let "count += 1"' . "\n"; ! $shell .= ' read TMPRELDIR' . "\n"; ! $shell .= ' RELDIR=`echo "$TMPRELDIR" | sed -e "s/[^/]*$//"`' . "\n"; ! $shell .= ' if [ "$NAME" == "END_OF_FILE_LIST_ZXC" ]' . "\n"; ! $shell .= ' then' . "\n"; ! ! // a quick check to see if we are in root (which would no be a good thing) if ( $this->incomingdir != '' || $this->incomingdir != '/' ) { ! $shell .= ' if [ -d "$SRCDIR" ]' . "\n"; ! $shell .= ' then' . "\n"; ! $shell .= ' rm -rf ' . addcslashes($this->incomingdir, $escape) . '/*' . "\n"; ! $shell .= ' rm -f "' . $tmpfile . "\"\n"; ! $shell .= ' fi' . "\n"; } - $shell .= ' exit 0' . "\n"; - $shell .= ' fi' . "\n"; - $shell .= ' move' . "\n"; - $shell .= ' let "count += 1"' . "\n"; - $shell .= 'done <"$filelist"' . "\n"; ! $this->command = $shell; $this->add_queue_command($shell, "bash"); --- 372,397 ---- $escape = "\ \\\*\+\[\]\^\$\(\)\{\}\=\!\<\>\|\:\#"; ! $srcdir = '"' . $this->incomingdir . '/"'; ! $dstdir = '"' . $this->incrementdir . '/"'; // get the date in .YYYY.DDD format $date = sprintf(".%04d.%03d", date("Y"), date("z")); ! $inc_list = '"' . $this->processdir . '/session/' . $this->session_id . ".incrementlist" . '"'; ! // a quick check to see if we are in root (which would no be a good thing!) if ( $this->incomingdir != '' || $this->incomingdir != '/' ) { ! $cleancmd = 'rm -rf ' . addcslashes($this->incomingdir, $escape) . '/*'; } ! $t = new rFastTemplate('.'); ! $t->define (array('content' => '../inc/templates/backup_increment_files.sh')); ! $t->assign ('SRCDIR', $srcdir); ! $t->assign ('DSTDIR', $dstdir); ! $t->assign ('DATE', $date); ! $t->assign ('INC_LIST', $inc_list); ! $t->assign ('CLEANCMD', $cleancmd); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); ! ! // add the script to command queue ! $this->command = $shell ; $this->add_queue_command($shell, "bash"); *************** *** 443,480 **** function server_create_index () { - /// - /// NOTE: this need error handling - /// - /// - - // create file index lists - $mindepth = ''; // no limit - $maxdepth = ''; // no limit - - // first we need a directory to work with. ! $this->current_folder = $this->incrementdir . '/' . $this->server . '/' . $this->share; ! $format = '///01'; ! // we start with the directories ! $type = "d"; // find directories ! $this->make_index($mindepth, $maxdepth, $type, $format); ! // then we make the file index(es) ! $type = "f"; // find files ! $this->make_index($mindepth, $maxdepth, $type, $format); ! // now for the current full backup dir ! $this->current_folder = $this->backupdir . '/' . $this->server . '/' . $this->share; ! $format = '///01.%AY.%Aj///02'; ! // we start with the directories ! $type = "d"; // find directories ! $this->make_index($mindepth, $maxdepth, $type, $format); ! // then we make the file index(es) ! $type = "f"; // find files ! $this->make_index($mindepth, $maxdepth, $type, $format); ! ! } --- 405,420 ---- function server_create_index () { // create file index lists // first we need a directory to work with. ! $filedir = $this->incrementdir . '/' . $this->server . '/' . $this->share; ! $date = ""; ! // create the db's for incrementals dirs ! $this->make_index($filedir, $date); // now for the current full backup dir ! $filedir = $this->backupdir . '/' . $this->server . '/' . $this->share; ! $date = "current"; ! $this->make_index($filedir, $date); } *************** *** 483,713 **** ////// ////// ! function make_index ($mindepth, $maxdepth, $type, $format) { ! ! // this will create a command that: ! // deletes the old index files ! // creates new index files. ! // create a list of file indexes (They will be seperated into 25000 line files) ! ! ! $result = ''; ! ! $find_cmd = "#!/bin/sh\n"; ! $find_cmd .= "# Automatically generated command\n"; ! $find_cmd .= "# Description: Generating index files\n"; ! $find_cmd .= "#\n"; ! ! /* if ($type == 'f') { ! // delete the old indexes before creating new ones ! $find_cmd .= "rm -f " . $this->current_folder . '.fileinde*' . "\n"; ! } else { ! // delete the dir index before creating a new one ! $find_cmd .= "rm -f " . $this->current_folder . '.dirindex*' . "\n"; ! } ! */ ! // get the file/folder list ! $find_cmd .= 'find "' . $this->current_folder . '/" -depth '; ! ! // include mindepth if set ! if($mindepth) { ! $find_cmd .= " -mindepth $mindepth "; ! } ! ! // include maxdepth if set ! if($maxdepth) { ! $find_cmd .= " -maxdepth $maxdepth "; ! } ! ! // define type to search for ! if($type) { ! $find_cmd .= "-type $type "; ! } ! ! // if type is "directories" ! if($type == 'd'){ ! $find_cmd .= ' -printf "%P\n"'; ! $find_cmd .= ' > "' . $this->current_folder . '.dirindex.raw"' ; ! ! } ! ! // if type is "file" ! if($type == 'f') { ! $find_cmd .= ' -printf "%h///00%f' . $format . '%s///03///FF\n"'; ! ! // pass the output though sed to correct some problem with the outout. ! // I want the files in the "root" dir to give the expected output (no slashes before or after dirname, except delimiters) ! // sed -e 's/^.\{43\}//g' -e '/^\/[^/]/s/^\///g' ! $find_cmd .= ' | sed -e \'s/^.\\{' ; ! $find_cmd .= (string)strlen($this->current_folder); ! $find_cmd .= '\\}//g\' -e \'/^\/[^/]/s/^\///g\''; ! ! // output into indexfile ! $find_cmd .= ' | sort > "' . $this->current_folder . '.fileindex.raw"' . "\n"; ! ! // create a list of indexes ! //$find_cmd .= 'find ' . $this->current_folder . '.fileindex.* -maxdepth 0 -type f -printf "%f\n" > "' . $this->current_folder . '.fileindexlist"' . "\n"; ! ! } ! ! // add the command to the command queue ! $this->command = $find_cmd; ! $this->add_queue_command($find_cmd, "bash"); ! // database and dir_tree creation ! if ($type == 'f') { ! // create databases for both dir indexes and file indexes ! ! $raw_file = $this->current_folder . ".fileindex.raw"; ! $file_db = $this->current_folder . ".fileindex.db"; ! $dir_db = $this->current_folder . ".dirindex.db"; ! $tree_file = $this->current_folder . ".dirtree.ser"; ! ! // ---------- START OF PHP SCRIPT ---------- ! $php_db_script = <<<END_OF_HEREDOC ! <? ! ! // create the dirindex and file index databases ! ! // set the max execution time (in seconds, 0 means no limit) ! set_time_limit(600); ! ! \$id = dba_open ('$file_db', "n", "db3"); ! if (!\$id) { ! echo "dba_open failed\\n"; ! exit; ! } ! // open the restore file index ! \$fp = fopen ('$raw_file',"r"); ! ! // empty input buffer ! \$input = ''; ! // set the start range ! \$range = 0; ! // read lines from the index file ! // PHP does not handle lines very well. So I read a line (Which in PHP terms is defined by <newline> ) ! // I check if it really is the end-of-line and if not, read again until we do. ! while(!feof(\$fp)) { ! \$input .= fgets(\$fp, 4096); ! // check if we have a complete line ! if ( substr(\$input, -6) == "///FF\\n" ) { ! // save results ! // each file get a range of 100 ! \$part = preg_split('/\/{3,3}(..)/', \$input, -1, PREG_SPLIT_DELIM_CAPTURE); ! // Now place the fields in an array with correct numbering ! \$i = 0; ! \$n = count(\$part); ! while ( \$n > \$i+3 ) { ! \$num = \$part[\$i+1]+\$range; ! dba_insert (\$num, \$part[\$i], \$id); ! \$i = \$i+2; ! } ! // clear input buffer to hold next line ! \$input = ''; ! // incremtent the range ! \$range = \$range+100; ! } ! } ! ! // insert a key to tell how many entries there are ! dba_replace ("index_count", \$counter-1, \$id); ! dba_close (\$id); ! ! ! // Now create the directory database ! ! \$id = dba_open ('$file_db', "r", "db3"); ! if (!\$id) { ! echo "dba_open failed\\n"; ! exit; ! } ! // create a new database. ! \$dir_id = dba_open ('$dir_db', "n", "db3"); ! if (!\$dir_id) { ! echo "dba_open failed\\n"; ! exit; ! } ! ! // set the first key ! \$ckey = 0; ! // set a fake prev_path ! \$prev_path = dba_fetch(\$ckey, \$id); ! \$path = \$prev_path; ! \$prev_ckey = 0; ! ! while ( \$ckey < \$range) { ! \$count++; ! \$path = dba_fetch(\$ckey, \$id); ! if ( \$path !== \$prev_path ) { ! dba_insert(\$prev_path, "range:\$prev_ckey:\$ckey|",\$dir_id); ! \$dir_tree[] = \$path; ! \$prev_path = \$path; ! \$prev_ckey = \$ckey; ! ! } ! \$ckey = \$ckey+100; ! } ! ! // insert the last entry which is not matched by the above loop ! \$ckey = \$ckey-100; ! dba_insert(\$prev_path, "range:\$prev_ckey:\$ckey|",\$dir_id); ! ! // close the databases ! dba_close (\$id); ! dba_close (\$dir_id); ! // close the file handle ! fclose(\$fp); ! ! //--------- create dirtree and save it as a serialized object ! ! // this magic marker _must_ be the same as in class_tree.php ! \$magic0 = '__///__0'; ! \$filelinks = parse_ini_file('$this->siteroot' . '/inc/filelinks.ini', process_sections); ! ! // $dirs = @file($this->dirtree); ! // sort the dirs (this is effective throughout the tree) ! sort(\$dir_tree); ! // reset the state tree ! \$state = ''; ! ! // parse the tree ! foreach (\$dir_tree as \$path ) { ! \$dir = explode('/', \$path); ! ! // check if the dir is a linkdir ! \$dircount = count(\$dir)-1; ! foreach ( \$filelinks as \$filelink ) { ! // if this is a linkdir then skip to next dir ! if ( strcasecmp(\$filelink["linkdir"], \$dir[\$dircount]) == 0 ) { ! continue 2; ! } ! } ! ! \$statestr = '\$state'; ! foreach ( \$dir as \$name ) { ! if (\$name != '' ) { ! \$name = addslashes(\$name); ! \$statestr .= '["' . \$name . '"]'; ! \$this_str = \$statestr . '["' . \$magic0 . '"] = "' . \$name . '";'; ! eval("\$this_str"); ! } ! } ! } ! ! // now serialize the dirtree and save it to disk ! \$serialized = serialize(\$state); ! \$fp = fopen('$tree_file',"w"); ! fwrite(\$fp, \$serialized, strlen(\$serialized)); ! fclose(\$fp); ! ! ! ?> ! END_OF_HEREDOC; ! // ------ END OF PHP SCRIPT ----------- ! $this->command = $php_db_script; ! $this->add_queue_command($php_db_script, "php"); ! } --- 423,452 ---- ////// ////// ! function make_index ($filedir, $date) { // database and dir_tree creation ! $file_db = $filedir . ".fileindex.db"; ! $dir_db = $filedir . ".dirindex.db"; ! $dir_ser = $filedir . ".dirtree.ser"; ! $file_links = $this->siteroot . "/inc/filelinks.ini"; ! $magic0 = $this->magic0; ! $root_dir = $filedir; ! $t = new rFastTemplate('.'); ! $t->define (array('content' => '../inc/templates/backup_create_databases.php')); ! $t->assign ('FILE_DB', $file_db); ! $t->assign ('DIR_DB', $dir_db); ! $t->assign ('ROOT_DIR', $root_dir); ! $t->assign ('DATE', $date); ! $t->assign ('MAGIC0', $magic0); ! $t->assign ('FILE_LINKS', $file_links); ! $t->assign ('DIR_SER', $dir_ser); ! $t->parse ('CONTENT', 'content'); ! $shell = $t->fetch(); ! ! // add the script to command queue ! $this->command = $shell ; ! $this->add_queue_command($shell, "php"); Index: class_files.php =================================================================== RCS file: /cvsroot/bobs/bobs/inc/class_files.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** class_files.php 14 Sep 2002 13:53:24 -0000 1.5 --- class_files.php 29 Oct 2002 03:15:42 -0000 1.6 *************** *** 48,54 **** // check if we have an empty dir ! if ( $indexes != "" ) { // fetch the files ! $this->data = $db->db_fetch_entries ( $indexes, $values ); } // parse the format if needed --- 48,54 ---- // check if we have an empty dir ! if ( $indexes != '' ) { // fetch the files ! $this->data = $db->db_fetch_entries ( $where, $indexes, $values ); } // parse the format if needed *************** *** 92,150 **** } ! function sort_files ($type) { ! ! // this will sort the array by name,size or date ! ! // check if the data array is empty ! if ( $this->data == '' ) { ! return; ! } ! switch($type) { ! case "name": ! $this->sort = 1; ! break; ! case "namerev": ! $this->sort = 4; ! break; ! case "date": ! $this->sort = 2; ! break; ! case "daterev": ! $this->sort = 5; ! break; ! case "size": ! $this->sort = 3; ! break; ! case "sizerev": ! $this->sort = 6; ! break; ! } ! // call the sort function ! usort($this->data, array($this,"sort_array")); ! // if we should reverse the sort ! if ( $type == "namerev" || $type == "daterev" || $type == "sizerev" ) { ! $tmp_arr = array_reverse($this->data); ! $this->data = $tmp_arr; } - return; - } - - function sort_array ($a, $b) { ! // sort function ! // this will sort the files array by a field number ! $field = $this->sort; ! if ( $field >= 4 ) { ! $field = $field-3; } - - if ( $a[$field] == $b[$field]) return 0; - return ($a[$field] < $b[$field]) ? -1 : 1 ; - } --- 92,150 ---- } ! function sort_files ($type) { ! // this will sort the array by name,size or date ! // check if the data array is empty ! if ( $this->data == '' ) { ! return; ! } ! switch($type) { ! case "name": ! $this->sort = 1; ! break; ! case "namerev": ! $this->sort = 4; ! break; ! case "date": ! $this->sort = 2; ! break; ! case "daterev": ! $this->sort = 5; ! break; ! case "size": ! $this->sort = 3; ! break; ! case "sizerev": ! $this->sort = 6; ! break; ! } ! ! // call the sort function ! usort($this->data, array($this,"sort_array")); ! ! // if we should reverse the sort ! if ( $type == "namerev" || $type == "daterev" || $type == "sizerev" ) { ! $tmp_arr = array_reverse($this->data); ! $this->data = $tmp_arr; ! } ! return; } ! function sort_array ($a, $b) { ! ! // sort function ! // this will sort the files array by a field number ! ! $field = $this->sort; ! if ( $field >= 4 ) { ! $field = $field-3; ! } ! if ( $a[$field] == $b[$field]) return 0; ! return ($a[$field] < $b[$field]) ? -1 : 1 ; } Index: class_restore.php =================================================================== RCS file: /cvsroot/bobs/bobs/inc/class_restore.php,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** class_restore.php 14 Sep 2002 13:53:24 -0000 1.10 --- class_restore.php 29 Oct 2002 03:15:42 -0000 1.11 *************** *** 283,287 **** // now we need to get the files. ! $filelist = array_merge($filelist, $db->db_fetch_entries($str, $values) ); } --- 283,287 ---- // now we need to get the files. ! $filelist = array_merge($filelist, $db->db_fetch_entries($where="restore", $str, $values) ); } *************** *** 358,366 **** $t->assign ('FILELIST', $fpname); ! foreach ( $dir_cmds as $dir ) { ! $t->assign ('DIR_CMDS', $dir); $t->parse ('DIRLIST', '.dirlist'); } - $t->parse ('CONTENT', 'content'); --- 358,371 ---- $t->assign ('FILELIST', $fpname); ! // check if we need to create any dirs ! if ( count($dir_cmds) > 1 || count($dir_cmds) == 1 ) { ! foreach ( $dir_cmds as $dir ) { ! $t->assign ('DIR_CMDS', $dir); ! $t->parse ('DIRLIST', '.dirlist'); ! } ! } else { ! $t->assign ('DIR_CMDS', ""); $t->parse ('DIRLIST', '.dirlist'); } $t->parse ('CONTENT', 'content'); *************** *** 403,407 **** // now we need to get the files. ! $filelist = array_merge($filelist, $db->db_fetch_entries($str, $values) ); } foreach ( $filelist as $file ) { --- 408,412 ---- // now we need to get the files. ! $filelist = array_merge($filelist, $db->db_fetch_entries($where="restore", $str, $values) ); } foreach ( $filelist as $file ) { Index: class_tree.php =================================================================== RCS file: /cvsroot/bobs/bobs/inc/class_tree.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** class_tree.php 14 Sep 2002 13:53:24 -0000 1.3 --- class_tree.php 29 Oct 2002 03:15:42 -0000 1.4 *************** *** 19,24 **** var $where = ''; // where are we (incremental, current .. etc) var $mtime = ''; // when was the dirindex last modified ! var $magic0 = '__///__0'; // what to use as magic text (you must be sure that no directories use this name) ! var $magic1 = '__///__1'; // what to use as magic text (you must be sure that no directories use this name) var $filelinks = ''; // list of linked files var $config; --- 19,24 ---- var $where = ''; // where are we (incremental, current .. etc) var $mtime = ''; // when was the dirindex last modified ! var $magic0 = ''; // what to use as magic text (you must be sure that no directories use this name) ! var $magic1 = ''; // what to use as magic text (you must be sure that no directories use this name) var $filelinks = ''; // list of linked files var $config; *************** *** 30,47 **** switch ($config[where]) { case "incremental": ! $this->dirtree = $config[incdirindex]; ! $this->tree_ser = $config[incdirtree]; break; case "current": ! $this->dirtree = $config[curdirindex]; ! $this->tree_ser = $config[curdirtree]; break; case "search": ! $this->dirtree = $config[processdir] . '/session/' . $config[session_id] . '.search.dirindex.db'; ! $this->tree_ser = $config[processdir] . '/session/' . $config[session_id] . '.search.dirtree.ser'; break; case "restore": ! $this->dirtree = $config[processdir] . '/session/' . $config[session_id] . '.restore.dirindex.db'; ! $this->tree_ser = $config[processdir] . '/session/' . $config[session_id] . '.restore.dirtree.ser'; break; } --- 30,47 ---- switch ($config[where]) { case "incremental": ! $this->dirtree = $config['incdirindex']; ! $this->tree_ser = $config['incdirtree']; break; case "current": ! $this->dirtree = $config['curdirindex']; ! $this->tree_ser = $config['curdirtree']; break; case "search": ! $this->dirtree = $config['processdir'] . '/session/' . $config['session_id'] . '.search.dirindex.db'; ! $this->tree_ser = $config['processdir'] . '/session/' . $config['session_id'] . '.search.dirtree.ser'; break; case "restore": ! $this->dirtree = $config['processdir'] . '/session/' . $config['session_id'] . '.restore.dirindex.db'; ! $this->tree_ser = $config['processdir'] . '/session/' . $config['session_id'] . '.restore.dirtree.ser'; break; } *************** *** 51,54 **** --- 51,57 ---- $this->server = $config["server"]; $this->share = $config["share"]; + + $this->magic0 = $config["magic0"]; + $this->magic1 = $config["magic1"]; $this->treehref = $newtreehref . '?where=' . $config["where"]; *************** *** 206,210 **** // display where we are ! $result .= "You are browsing the <b> " . $this->where . "</b> directories of <b>" . $this->server . '/' . $this->share . "</b><br>"; --- 209,213 ---- // display where we are ! $result .= "You are browsing the <b>" . $this->where . "</b> directories of <b>" . $this->server . '/' . $this->share . "</b><br>"; *************** *** 403,407 **** eval($statestr); } - return; } --- 406,409 ---- |