Link to home
Start Free TrialLog in
Avatar of Vincent D
Vincent DFlag for United States of America

asked on

Script to copy folder content every 5 minutes

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?
Avatar of rushtoshankar
rushtoshankar
Flag of United States of America image

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.
Avatar of Bill Prew
Bill Prew

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
Avatar of Vincent D

ASKER

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?
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.