Solved

Copying Multiple Directories, then verifying the transfer with Perl ?

Posted on 2001-06-17
9
176 Views
Last Modified: 2010-03-05
Okay, heres the prob I have, I am just not sure if its possible.

I want a user to log on to their intranet "back up page"

then specify which directory they want to back up on their part of the server. Then the script will need to transfer that directory (unfortunately including subdirs and files) to another location, then if the data transfer was successful then delete the dirs/files that were backed up.

This is on a network, where the server has full rights/permissions. But I dont think that perl can transfer multiple subdirs ? so I was thinking along the lines of the perl script calling maybe a batch file in order to copy information (but then I remembered that perl cant talk to batch files, or cant it), it was these point that I thought sheesh,

lets ask the experts :)
0
Comment
Question by:scooter41
  • 4
  • 3
  • 2
9 Comments
 
LVL 8

Expert Comment

by:bebonham
ID: 6200416
perl can do what you want, or you can use the system() or ` operator to run any batch file or commands straight from the perl.

if this is win32 and you don't want to get to technical,

just get the root directory to backup
and do
`xcopy $dirname newdir`;

if you want to be more technical, you can open each file and write it to a new location.

but I think at this point I would just use the commands made available by the os.

Bob
0
 

Author Comment

by:scooter41
ID: 6201099
okay bob, thats brilliant, thanks for your help so far, but just one thing still remains, how do i check that the copy has been 100% error free before deleting ? the data will be important docs and is vital that it cannot be deleted unless backed up error free.

Do you think i could just take the properties of the two dirs for example and compare them ?
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6201230
just compare files' sizes.
0
 
LVL 8

Accepted Solution

by:
bebonham earned 200 total points
ID: 6204899
well, I mean

in the event that the file wouldn't be ok ?!?

99.99 unlikely

then the chance of the size being right but one character being switched is probably 99.99 so file size would still let .00001% corrupt files through :)


personally, I have never seen it happen put you can use

$nfilesize=${[stat $newFile]}[7];
$ofilesize=${[stat $oldFile]}[7];
if($nfilesize!=$ofilesize)
{
die('ohmyGosh')
}




Bob
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:scooter41
ID: 6205230
Thanks Bob !
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6206845
if course getting the file size is easier with -s

die ("bla...!\n") if ( (-s $newfile) != (-s $oldfile) );
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6208883
thanks shlomoy!

I just learned stat :)

funny how in perl, seems like everybody is good at different stuff...

just wish I new the basics a little better.

especially the mysterious (to me) pipe and fork.

Bob
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6209047
to learn more about pipe and fork read:

       pipe READHANDLE,WRITEHANDLE
               Opens a pair of connected pipes like the
               corresponding system call.  Note that if you set
               up a loop of piped processes, deadlock can occur
               unless you are very careful.  In addition, note
               that Perl's pipes use stdio buffering, so you may
               need to set `$|' to flush your WRITEHANDLE after
               each command, depending on the application.

               See the IPC::Open2 manpage, the IPC::Open3
               manpage, and the Bidirectional Communication entry
               in the perlipc manpage for examples of such
               things.

               On systems that support a close-on-exec flag on
               files, the flag will be set for the newly opened
               file descriptors as determined by the value of
               $^F.  See the section on "$^F" in the perlvar
               manpage.          











       fork    Does a fork(2) system call to create a new process
               running the same program at the same point.  It
               returns the child pid to the parent process, `0'
               to the child process, or `undef' if the fork is
               unsuccessful.  File descriptors (and sometimes
               locks on those descriptors) are shared, while
               everything else is copied.  On most systems
               supporting fork(), great care has gone into making
               it extremely efficient (for example, using copy-
               on-write technology on data pages), making it the
               dominant paradigm for multitasking over the last
               few decades.

               Beginning with v5.6.0, Perl will attempt to flush
               all files opened for output before forking the
               child process, but this may not be supported on
               some platforms (see the perlport manpage).  To be
               safe, you may need to set `$|' ($AUTOFLUSH in
               English) or call the `autoflush()' method of
               `IO::Handle' on any open handles in order to avoid
               duplicate output.

               If you `fork' without ever waiting on your
               children, you will accumulate zombies.  On some
               systems, you can avoid this by setting
               `$SIG{CHLD}' to `"IGNORE"'.  See also the perlipc
               manpage for more examples of forking and reaping
               moribund children.

               Note that if your forked child inherits system
               file descriptors like STDIN and STDOUT that are
               actually connected by a pipe or socket, even if
               you exit, then the remote server (such as, say, a  
               CGI script or a backgrounded job launched from a
               remote shell) won't think you're done.  You should
               reopen those to /dev/null if it's any issue.                                        
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6209049
these man pages will also be useful:

perldoc perlipc
perldoc perlfork
perldoc -f open



(you can also look those up in www.perldoc.com)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now