From: Rene R. <ren...@us...> - 2002-10-29 03:15:48
|
Update of /cvsroot/bobs/bobs/inc/templates In directory usw-pr-cvs1:/tmp/cvs-serv14737/inc/templates Added Files: backup_create_databases.php backup_increment_files.sh backup_nfs_backup_files.sh backup_nfs_mount_server.sh backup_nfs_unmount_server.sh backup_smb_backup_files.sh backup_smb_mount_server.sh backup_smb_unmount_server.sh 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. --- NEW FILE: backup_create_databases.php --- <?php // create the dirindex and file index databases // set the max execution time (in seconds, 0 means no limit) set_time_limit(600); class create { var $id = ''; // database handle function create ( $db ) { $this->id = dba_open ($db, "n", "db3"); return; } function closedb () { dba_sync($this->id); dba_close ($this->id); return; } // this function will recursively parse the dirs function getdirList ($dirname, $len, $range, $date) { $d = dir($dirname); // we need to get the files in the current dir befor moving on to subdirs while($entry = $d->read()) { if ($entry != "." && $entry != "..") { if (is_dir($dirname."/".$entry)) { $dirs[$i++] = $dirname . "/" . $entry; } else { $f++; $files[$f]['name'] = $entry; $files[$f]['dir'] = $dirname; } } } if ( isset($files) ) { foreach ($files as $file ) { // insert the file into the db // insert the path $num = $range; dba_insert ($num, substr($file['dir'],$len), $this->id); // insert name $num = $range+1; dba_insert ($num, $file['name'], $this->id); // insert date if it is not part of the filename (it is in incremental files) if ( $date == "current" ) { $num = $range+2; $stamp = filemtime ($file['dir'] . '/' . $file['name']); $filedate = sprintf(".%04d.%03d", date("Y", $stamp), date("z", $stamp)); dba_insert ($num, $filedate, $this->id); } // insert filesize $filesize = filesize($file['dir'] . '/' . $file['name']); $num = $range+3; dba_insert ($num, $filesize, $this->id); //increment the range $range = $range+100; } } unset($files); if ( isset($dirs) ) { foreach($dirs as $dirnames) { $range = $this->getdirList($dirnames, $len, $range, $date); } } unset($dirs); $d->close(); return $range; } } $db = '{FILE_DB}'; $c = new create($db); $rootdir = '{ROOT_DIR}'; $len = strlen($rootdir)+1; $range = 0; $date = "{DATE}"; $range = $c->getdirList($rootdir, $len, $range, $date); $c->closedb(); // Now create the directory database // open the file index db $id = dba_open($db, "r", "db3"); if (!$id) { echo "dba_open failed\n"; exit; } // create a new dir 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) { $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; } // increment the key $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); //--------- create dirtree and save it as a serialized object // this magic marker _must_ be the same as in class_tree.php $magic0 = '{MAGIC0}'; $filelinks = parse_ini_file('{FILE_LINKS}', process_sections); // 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('{DIR_SER}',"w"); fwrite($fp, $serialized, strlen($serialized)); fclose($fp); ?> --- NEW FILE: backup_increment_files.sh --- #!/bin/bash # increment files in incoming #SRCDIR="/backup/bobsdata/incoming/" SRCDIR="{SRCDIR}" #DSTDIR="/backup/bobsdata/incremental/" DSTDIR="{DSTDIR}" DATE="{DATE}" # clear the filelist if it exists rm -f "{INC_LIST}" find "$SRCDIR" -type f -printf "%f\n%P\n" >> "{INC_LIST}" echo "END_OF_FILE_LIST_ZXC" >> "{INC_LIST}" echo "END_OF_FILE_LIST_ZXC" >> "{INC_LIST}" filelist="{INC_LIST}" move () { if [ -d "$DSTDIR$RELDIR" ] then `mv "$SRCDIR$RELDIR$NAME" "$DSTDIR$RELDIR$NAME$DATE"` else `mkdir --parents "$DSTDIR$RELDIR"` `mv "$SRCDIR$RELDIR$NAME" "$DSTDIR$RELDIR$NAME$DATE"` fi } count=0 while [ "$NAME" != "END_OF_FILE_LIST_ZXC" ] do read NAME let "count += 1" read TMPRELDIR RELDIR=`echo "$TMPRELDIR" | sed -e "s/[^/]*$//"` if [ "$NAME" == "END_OF_FILE_LIST_ZXC" ] then if [ -d "$SRCDIR" ] then {CLEANCMD} rm -f "{INC_LIST}" fi exit 0 fi move let "count += 1" done <"$filelist" --- NEW FILE: backup_nfs_backup_files.sh --- #!/bin/bash # Generated script. # This will backup files from an nfs share if [ -e "{LOCKFILE}" ] then echo "{SESSION_ID}.Running backup" >> "{SHSTATS}" {BACKUP_CMD} echo "{SESSION_ID}.Finished backup" >> "{SHSTATS}" exit fi --- NEW FILE: backup_nfs_mount_server.sh --- #!/bin/bash # Description: Mount the nfs share echo "{SESSION_ID}.Preparing backup" >> "{SHSTATS}" mkdir -p "{MOUNTDIR}" if [ -d "{MOUNTDIR}" ] then {MOUNT_CMD} if [ $? -eq 0 ] then touch "{LOCKFILE}" echo "{SESSION_ID}.Finished preparing backup" >> "{SHSTATS}" exit fi fi --- NEW FILE: backup_nfs_unmount_server.sh --- #!/bin/bash # Generated script # this will unmount a server and remove the lock file if [ -a "{LOCKFILE}" ] then umount "{MOUNTDIR}" rm -f "{LOCKFILE}" exit fi --- NEW FILE: backup_smb_backup_files.sh --- #!/bin/bash # Generated script. # This will backup files from a smb share if [ -e "{LOCKFILE}" ] then echo "{SESSION_ID}.Running backup" >> "{SHSTATS}" {BACKUP_CMD} echo "{SESSION_ID}.Finished backup" >> "{SHSTATS}" exit fi --- NEW FILE: backup_smb_mount_server.sh --- #!/bin/bash # Description: Mount the smb share echo "{SESSION_ID}.Preparing backup" >> "{SHSTATS}" mkdir -p "{MOUNTDIR}" if [ -d "{MOUNTDIR}" ] then {MOUNT_CMD} if [ $? -eq 0 ] then touch "{LOCKFILE}" echo "{SESSION_ID}.Finished preparing backup" >> "{SHSTATS}" exit fi fi --- NEW FILE: backup_smb_unmount_server.sh --- #!/bin/bash # Generated script # this will unmount a server and remove the lock file if [ -a "{LOCKFILE}" ] then umount "{MOUNTDIR}" rm -f "{LOCKFILE}" exit fi |