Solved

Script to copy folder content every 5 minutes

Posted on 2012-04-05
7
2,831 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 53

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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 53

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA & VBSCRIPT: re-adapt log file 13 33
Bat File Script - HELP 2 27
Use GPO script to report finding a certain file 16 15
Raising Forest Functional Level 9 37
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…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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