Solved

Script to copy folder content every 5 minutes

Posted on 2012-04-05
7
2,380 Views
Last Modified: 2012-09-26
Hi,

We have a folder on a particular server that moves files in and out of a particular folder all day long. We would like to use a batch file/script that would copy all content to an archive folder somewhere else on the server/network just as a precaution.

Can anyone direct us to examples of batch files/scripts that work great for such a task?
0
Comment
Question by:Vincent D
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37813170
paste the following lines in a bath file

@echo off
xcopy C:\Source\Folder  Z:\Destination\Folder /s /e

You can use the task scheduler to call this batch file every 5 minutes or (your desired time).

z:\ can be any local drive or network shared drive.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 37813175
Why not just create a simple BAT file with the COPY commands (or XCOPY) that you need to copy the files, and then use Windows Scheduler to run it every 5 minutes.

If you need help with the exact syntax and options for the COPY, we'll need a little more info about what files are involved, how are they selected, are there subfolders, are they moved / deleted or copied, etc.

~bp
0
 

Author Comment

by:Vincent D
ID: 37813800
It is a bit more complicated as the files that show up in this folder on this particular Server 2003 server are periodically transferred from another server thru a batch process that runs periodically. The files that show up are only in the target folder for a short (5min) period of time before being moved out of the target folder and on to another third server.

Would using the batch file copy process reliably get all files without running into issues?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Vincent D
ID: 37813815
Scenario Example which has files coming and going to and from all 3 servers

Server A = Redhat Linux Server with Samba
Server B = Windows 2003 Server (that contains target folder we are looking to archive EVERYTHING that comes in and out of it). One folder for incoming and another seperate folder for outbound.
Server C=Hosted by third party thru secure internet VPN link.
0
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37813918
xcopy is a reliable program. The only thing is that the time window you said 5 mins should be enough to copy the intermediate files. If you have larger/too many files, it may not work.
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 37813997
Based on what you describe, I think the approach you are contemplating is going to miss files now and then.  Here's the problem.  The existing process that moves the files out of the folder you want to "watch", runs periodically and removes all files.  If your job doesn't run at the last instant before that existing process, then a file could be added after your copy process runs, and then be removed from the folder by the existing process, and you won't see it.

Is there anyway to modify the existing copy process to add a step that does the archiving you want?

If not then, you could look at some type of monitoring tool that exists, that can watch the folder involved more frequently, like every few seconds, looking for new files and saving a copy off.

One other problem you are likely to run in to is that files will likely be added to the directory in the folder before all of their content is copied in.  So you might occasionally get some files that are not "completed" yet.

Here are some examples of directory monitoring utilities if you want to check them out.

===== FREE =====

http://www.brutaldev.com/page/Directory-Monitor.aspx
http://download.cnet.com/Directory-Monitor/3000-2248_4-10849871.html

http://www.contactplus.com/products/freestuff/monidir.htm

http://www.nodesoft.com/foldermonitor

http://www.gibinsoft.net/

http://leelusoft.blogspot.com/2010/07/watch-4-folder-22.html


===== $$$$ =====

http://www.watchdirectory.net/

http://www.coolutils.com/TotalFolderMonitor

http://www.networkautomation.com/

http://www.liquidmirror.com/alwayswatching.asp

~bp
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37815774
If you are able to use Powershell, you can also use the FileSystemWatcher class to monitor a folder for changes, and act accordingly.  See here for an example:
http://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b

Ultimately though, I agree with Bill....the best way to ensure accuracy would be to modify your incoming and outgoing automatic processes (batch files?) to add the archiving code to them.

Regards,

Rob.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

23 Experts available now in Live!

Get 1:1 Help Now