Gossamer Forum
Quote Reply
BackUP
I have a backup subroutine on one of my script,
I can backup all the files in a certain directory to
the backup directory.

the problem is it can only copy the files in that data directory but the script can't copy if the data directory
has a subdirectories.

How can I possiably change the script so that I can
backup a directory which all files and files
in the subdirectories can backup (copy the subdirectory
and the files without changing the layout format)
in the backup directory..

Below is the backup subroutine of my script..
please give me some advice and suggestions for how to change
the script!


------------------------------------------------------------
sub backup {

$board_id = $FORM{'board_id'};
$board_dir = "$dbm_dir$board_id";
$backup_log_file = "$backup_dir$backup_log";

$gap="##,,";

#如果目錄不存在則建立討論區備份目錄
if(-d "$backup_dir$board_id") {
#目錄已存在
} else {
mkdir("$backup_dir$board_id", 0777) || errormesg("cannot makedir $backup_dir$board_id : $!");
chmod(0777,"$backup_dir$board_id") || errormesg("cannot chmod $backup_dir$board_id : $!");
}
#開啟備份記錄檔
open (LOG_FILE,">$backup_dir$backup_log");

#備份 TXT 檔案
opendir(DIR,"$dbm_dir");
@txt_file=grep(/\w/,readdir(DIR));
foreach $txt_file (@txt_file) {

if($txt_file =~ /^\d/) {

print LOG_FILE "start backup $dbm_dir$board_id/$txt_file";
open (FILE,"$dbm_dir$txt_file");
@line=<FILE>;
close (FILE);

open (FILE,">$backup_dir$board_id/$txt_file");
foreach (@line){
print FILE "$_\n";
}
close (FILE);
print LOG_FILE "........ completed \n";
}
}

#備份 DBM 檔案
@backup_data = (news_data,post_data,subject_data,s_post_data,s_subject_data); #備份資料列表

foreach $backup_file (@backup_data) {
print LOG_FILE "start backup $dbm_dir$backup_file ";
dbmopen (湦A,"$dbm_dir$backup_file",0666) || errormesg("無法開啟 $dbm_dir$board_id/$backup_file");
%temp=湦A;
dbmclose (湦A);

@data_entry=keys %temp;

foreach $entry(@data_entry) {

@temp1=split(/$gap/,$temp{$entry});
$temp2=$entry."$gap";
$temp2=$entry."$gap".$temp{$entry};
$temp2 =~ s/\n//g;
push (@output,$temp2);
}
$output_file="$backup_file.html";



open (FILE,">$backup_dir$board_id/$output_file") || errormesg("無法開啟 $dbm_dir$board_id/$output_file");
foreach (@output){
print FILE "$_\n";
}
close (FILE);
@output="";
print LOG_FILE "........ completed \n";

}
return_url("$edit_url?board_id=$board_id\&type=admin");
}
-----------------------------------------------------------

please give me some advice and suggestions for how to change
the script!