Solved

Script to copy folder content every 5 minutes

Posted on 2012-04-05
7
2,492 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 52

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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 52

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Learn about cloud computing and its benefits for small business owners.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 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

21 Experts available now in Live!

Get 1:1 Help Now