Title: Re: Backup/Restore
Post by Dieter Werner on 01/03/06 at 12:37:38
Here comes the file ... :)
Code:
#!/usr/bin/perl #-############################################# # backup_restore.pl # Date: 08/03/2001 # Version: eA-1.6.1.60 # Last update: 01/03/2006 #-############################################# # Copyright (C) 2001-2006 by Dieter Werner # http://www.everyscript.de # All rights reserved by the author. #-############################################# # # NON-COMMERCIAL LICENSE: # # So long as you come to an understanding with the following rules # # 01. You may not distribute/redistribute this software for money. # 02. You may not alter and/or remove the content of this license. # 03. You may not alter the code and then sell it under another name. # 04. You may not remove any copyright notices regarding the author. # 05. You may not alter and/or remove the content of the warranty notice. # 06. You may not use parts of this software as a part of any other software. # 07. You may not use this software as a part of a commercial auction system. # 08. You may not sell this software as a part of an other product you are selling. # 09. You may not give away this software for money in any way and/or any kind. # 10. You may not use any billing and/or accounting software with or beside this software. # 11. You may not distribute/redistribute this software without the items of this non-commercial license. # # so long you can use, distribute/redistribute and/or modify this software for free. # #-############################################# # In other words: # ASK me before you start making money with my work!! #-############################################# # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # #-############################################# # # USAGE: # #-############################################# # # - Edit the value of $config{'basepath'} of this script # # - Save this file as backup_restore.pl to your cgi-bin directory # # - Run it by typing: # http://YourDomain/cgi-bin/backup_restore.pl?action=backup # or # http://YourDomain/cgi-bin/backup_restore.pl?action=restore # #-############################################# # OK - Here we go ...
#-############################################# # Setup Environment #-############################################# BEGIN { print "Content-type: text/html\n\n"; $0 =~ m~(.*)/[^/]+~ || $0 =~ m~(.*)\\[^\\]+~; unshift @INC, $1; $ENV{'CGI_STORE'} = 'backup_restore'; }
#-############################################# # Use-Section #-############################################# use strict; use warnings; use vars qw(%config %form); #-############################################# # Setup Variables #-############################################# $|++; local (%config, %form); # replace this line with your $config{'basepath'} $config{'basepath'} = "d:/inetpub/wwwroot/eAuction161"; #-############################################# # Get the Server-OS #-############################################# if ($ENV{'WINDIR'} or $ENV{'WINBOOTDIR'} or $^O eq 'MSWin32' or $^O eq 'NT') { $config{'op_system'} = 1; $config{'flock'} = 1; } else { $config{'op_system'} = 2; $config{'flock'} = 1; } #-############################################# # Prepare-Section #-############################################# get_form_data(); get_config(); backup_restore_data(); delete $ENV{'CGI_STORE'}; #-############################################# sub backup_restore_data { #-############################################# my ($dir, $backup_dir, $file, $root_dir, $backup_path); my (@all_dirs, @allfiles, @fileval); if ($form{'action'} eq 'backup') { $root_dir = $config{'basepath'}; $backup_path = $config{'backup_path'}; } elsif ($form{'action'} eq 'restore') { $root_dir = $config{'backup_path'}; $backup_path = $config{'basepath'}; } else { return; } disp_message('start'); $root_dir =~ /\/$/ && chop $root_dir ; $backup_path =~ /\/$/ && chop $backup_path; @all_dirs = get_all_dirs($root_dir); foreach $dir (@all_dirs) { ($backup_dir = $dir) =~ s/$root_dir/$backup_path/; unless (-d $backup_dir) { umask(000); mkdir($backup_dir, 0777); alert_admin(0, "unable to create $backup_dir <br>$!") unless -d $backup_dir; } opendir TO_BACKUP, $dir or alert_admin(0, "unable to open $dir <br>$!"); @allfiles = grep /\.\w{3,}$/, readdir TO_BACKUP; closedir TO_BACKUP; foreach $file (@allfiles) { open THEFILE, "< $dir/$file" or alert_admin(0, "unable to read $dir/$file <br>$!"); binmode THEFILE; flock THEFILE, 2 if $config{'flock'}; @fileval = <THEFILE>; close THEFILE; print "eA-Dir: $dir File: $file<br>"; open BACKUPFILE, "> $backup_dir/$file" or alert_admin(0, "unable to write the file $backup_dir/$file <br>$!"); binmode BACKUPFILE; flock BACKUPFILE, 2 if $config{'flock'}; print BACKUPFILE @fileval; close BACKUPFILE; print "Dir: $backup_dir File: $file<br>"; } } disp_message($form{'action'}); } #-############################################# sub get_config { #-############################################# my ($dir, @temp); $ENV{'SCRIPT_NAME'} !~ /$ENV{'CGI_STORE'}/ && return; $config{'basepath'} =~ /\/$/ && chop $config{'basepath'}; $config{'backup_path'} = $config{'basepath'}; @temp = split /\//, $config{'basepath'}; $dir = pop @temp; $config{'backup_path'} = join "\/", @temp; $config{'backup_path'} .= "/$dir" . "_backup/"; } #-############################################# sub get_all_dirs { #-############################################# my ($the_dir, $all_dirs) = @_; my @sub_dirs = (); my $part; push @$all_dirs, $the_dir; opendir DIR, $the_dir; readdir DIR for 0..1; @sub_dirs = grep ! /\.\w+$/, readdir DIR; closedir DIR; foreach $part (@sub_dirs) { $ENV{'SCRIPT_NAME'} !~ /$ENV{'CGI_STORE'}/ && return; get_all_dirs("$the_dir/$part", $all_dirs) if (-d "$the_dir/$part"); } return @$all_dirs; } #-############################################# sub disp_message { #-############################################# my $flag = shift;
my $donotdelete = <<EO_HTML; <br><br> <hr width="30%"> <font face="Arial" color="#000080" size="1">Copyright 2001 by<br> <a href="mailto:info\@everyscript.de">Dieter Werner</a></font> <hr width="30%"> </div> EO_HTML print <<EO_HTML if $flag eq 'start'; <div align="center"> <br><br> <hr width="30%"> <br> <font face="Arial" size="3" color="#000080"> <b>Hello Admin - I'm working for you ...</b></font> <br><br> <hr width="30%"> </div> EO_HTML print <<EO_HTML if $flag eq 'backup'; <div align="center"> <br> <font face="Arial" size="3" color="#000080"><b>Auction-Backup successfully done</b></font> $donotdelete EO_HTML
print <<EO_HTML if $flag eq 'restore'; <div align="center"> <br> <font face="Arial" size="3" color="#000080"><b>Backup-Files successfully restored</b></font> $donotdelete EO_HTML }
#-############################################# sub alert_admin { #-############################################# my ($flag, $message) = @_; print <<EO_HTML; <div align="center"> <hr width="400" size="1" color="#000088" noshade> <font face="arial" size="2" color="#FF0000"><b>ERROR</b></font><br> <font face="arial" size="2" color="#000088">$message<br><br> <hr width="400" size="1" color="#000088" noshade> </div> EO_HTML exit; } #-############################################# sub get_form_data { #-############################################# my ($buffer, $temp, @part);
$ENV{'SCRIPT_NAME'} !~ /$ENV{'CGI_STORE'}/ && return; foreach $temp (split /\&/,$ENV{'QUERY_STRING'}) { $temp =~ s/\+/ /g; $temp =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; $temp =~ s/[\r\n]//g; @part = split /\=/, $temp, 2; $form{$part[0]} = $part[1]; } $form{'action'} = 'nodata' unless $form{'action'}; } #-############################################# exit; #-############################################# |
|
|