Solved

Script to copy folder content every 5 minutes

Posted on 2012-04-05
7
3,139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 54

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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 54

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…

752 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