All Scripts backed by 8 years in business, free support, free updates and a 30 day money back guarantee.
Download Purchase Programming F.A.Q. Support Contact
Commercial Perl Scripts
All Form Pro
Count It
Form Mailer + Attachments
Client File Manager
Da Godfaddah
Dropbox
FAQ Builder
ManageHT
RegisterHT
Mailing Bank
Page Updater - Text
Page Updater - WYSIWYG
PS Guestbook
PS Lightning Search
Quick File Mailer
Quick MySQL
Select-A-File
Upload Center
Free Perl Scripts
Access Log Viewer
All Form
Epoch Converter
Error Log Viewer
Invoice Center
PS Upload
Question Manager
Quick CHMOD
QuickHT
Site File Finder
Site File Lister
SSI Tag Maker
Perl Modules
Monger Calendar
Monger File
Monger Mail
Monger Persist
JavaScript Generators
PopUp Windows
Meta Gen
RGB / Hex Converter
Page Colors
Sudoku
Tutorials and FAQs
Cookies
Using CuteFTP
Using WS_FTP
Installing Scripts
Debugging
Utilities
env_vars.pl
backup.pl
restore.pl
check_email.pl
date.pl
dayname.pl
fileage.pl
format_length.pl
format_url.pl
getfile.pl
parse.pl
redirect_html.pl
Free Services
Epoch Converter
TLD Registries
RGB/Hex FInder
Colour Checker
ASCII Codes

Form Processor with no SPAM from robots.

Anti-spam, anti-robot, anti-flame, Guestbook for your website.

Manage Remote websites from your website. Allow clients to update sections of their own web pages.
Utility Name: backup.pl
restore.pl
Platform: UNIX or Linux
Requires: Perl4 or higher


Many CGI programs suffer the unfortunate demise of having too many people try to access it at the same time. When this happens, data files tend to get erased. Once that data is gone, unless you backed it up to your desk top computer, it's gone!

One solution is to use a flocking command "flock()" or to use lock and unlock files. Both of these are good but neither guarantee 100% safety. Therefore I have developed two utilities that are easily used to backup files and restore lost data. It's not 100% guaranteed either but when used in conjunction with one of these other protection methods then it goes a long way to reducing most of the risk!

backup.pl : backup([file_abs_path])
This utility will take an existing file on your Unix server and make a backup copy of it. It creates a file with an identical name, in the same directory but the extension is changed to ".bak". I write in the program that every time a critical file is generated or updated, it also gets backed up. This backup utility requires only one parameter be passed to it. This parameter is the absolute path to the file that you want backed up.

restore.pl : @contents = restore([file_abs_path])
This utility, when called, will search the directory in question for a backup file (file same name but extension of ".bak"). If the backup file is found the utility then restores the original files contents as they were when it was last backed up. The program then returns from the subroutine the contents of the file.

As you can see, these two utilities were designed to be used to together but they don't have to be used together.

Here is an example of the backup of a file:

if(open(BITS, ">$DataPath/parts/catalogue.file")) {
    flock(BITS, '2');
    print BITS "$entry\n";
    close(BITS);
    backup("$DataPath/parts/catalogue.bak");
}

if you were using my 'fileadd.pl' utility then it would look like this:

fileadd("$DataPath/parts/catalogue.file", "$entry");
backup("$DataPath/parts/catalogue.file");

This will now make two files in the directory 'parts', they are:

catalogue.file and catalogue.bak


Here is an example of restoring a file. Two examples, one plain coding and the second using my 'getfile.pl' utility:

if(open(BITS, "<$DataPath/parts/catalogue.file")) {
    flock(BITS, '2');
    @contents = ;
    close(BITS);
    if(!$contents[0]) {
	@contents = restore("$DataPath/parts/catalogue.file");
    }
}

....or....

@contents = getfile("$DataPath/parts/catalogue.file");
if(!$contents[0]) {
    @contents = restore("$DataPath/parts/catalogue.file");
}

  ©2008 PerlServices.net. All Content and Media. Site hosted by LinuxHostingPlans.com