• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2079
  • Last Modified:

How to ensure 'xcopy' completed and successfully in Perl script?

I use 'xcopy' to copy directory trees and files to another archiving server.
Before I use 'rd' to remove directories and all contents, I have to ensure the
'xcopy' completed and successfully, which means it didn't have any missing
or corrupted archive files during 'xcopy'.  How to verify the 'xcopy' successfully
to avoid data loss before doing 'rd' in Perl script?

system("xcopy $originalDataDir $archiveFolder /e /y /i /k /q");
system("rd /s /q $originalDataDir");
0
yc_yc
Asked:
yc_yc
  • 3
  • 3
  • 2
1 Solution
 
matrixnzCommented:
Hi yc_yc

Recommend robocopy over xcopy it has more functionality + is ideal for creating backups, if a file fails you can request it continues trying until it completes etc...  It can be found on Windows 2003 Resource Kit Download, more info here http://www.ss64.com/nt/robocopy.html

Cheers
0
 
FishMongerCommented:
Since you're using a Perl script, I'd use Perl methods instead of xcopy or robocopy.

File::Copy::Recursive will copy the dir tree and if there is a failure on any portion of the copy process, it will stop and return false.  You can do it in a 2 step process like you're currently doing by using the dircopy() and pathrm() methods.  Or, you can do it in a single step with the dirmove() method.

http://search.cpan.org/~dmuey/File-Copy-Recursive-0.33/Recursive.pm
0
 
FishMongerCommented:
You can also look at using the File::Xcopy module, which would be my next choice after File::Copy::Recursive.

http://search.cpan.org/~geotiger/File-Xcopy-0.12/Xcopy.pm
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
FishMongerCommented:
To answer you question more directly, you need to check the return value of the system call.

See perldoc -f system

Quoted from the doc:
               The return value is the exit status of the program as returned by the "wait"
               call.  To get the actual exit value shift right by eight (see below).  See also
               "exec".  This is not what you want to use to capture the output from a command,
               for that you should use merely backticks or "qx//", as described in "√ĘSTRING√Ę"
               in perlop.  Return value of -1 indicates a failure to start the program
               (inspect $! for the reason).
0
 
yc_ycAuthor Commented:
Matrixnz,

Thanks for your recommend. I started to learn how to use it. Since the download 'windows resource kits 2003 Server' in Microsoft website cannot be installed on windows 2000, I found the 'robocopy.exe' from the following link: http://www.soloenterprises.org/tips-and-tricks/robocopy.php
Do you think the application robocopy I got from above link shall be fine?

Also, do you think the following command with selected options is good enough to handle directories and files copied from source to destination server?

$robocopy $sourceServer $archiveServer /COPY:DATA /ZB /E /NFL /NDL /NP /LOG:$roboLog

Thanks
0
 
matrixnzCommented:
Hi yc_yc

The install shouldn't be OS dependant, I have Windows 2003 Resource Kit installed on my XP machine, maybe it was a windows installer problem.  If you have a Windows XP machine then recommend expanding it and copying the relavent files or install RoboCopy GUI http://www.microsoft.com/technet/technetmag/issues/2006/11/UtilitySpotlight/ which basically has Robocopy included.  Not saying that the copy you have is incorrect, but it's difficult to verify if it's the latest version or not.

Anyway I digress, from what you suggest it does look ok, however I'd use /COPYALL to ensure all the information is pulled across including Security, Owner and Audting Info.  If you only wish to collect the data than you'd just need the switch /COPY:D rather than /COPY:DATA unless you meant /COPY:DAT which you shouldn't need as this is the default.

Cheers
0
 
yc_ycAuthor Commented:
matrixnz,

The windows 2003 Resource Kit need have XP or later windows version to be able to install.
The 'robocopy' application version is 5.1.1.1010, which was downloaded from my last email's link.

The script will be run by the window system tools 'Scheduled Tasks' on a local PC.
Do you think if it is all right to run a script scheduled on a local PC that uses command 'robocopy'
to handle data archiving from source server to destination server through network?

Thanks
0
 
matrixnzCommented:
Hi yc_yc

Yes that's fine, we have a number of users that do it this way, there are other ways of scripting it as well but adding to 'Scheduled Tasks' is fairly common practice.

Cheers
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now