Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Move a folder from one server to another using a vb script, bat or cmd

Posted on 2010-08-30
8
Medium Priority
?
466 Views
Last Modified: 2012-05-10
I have a folder c:\backups on server name ares that I want to move to a mapped drive J:\temp\backups.  J: drive is a mapped drive to another server named dellbackup.  I need a .vbs, .bat or .cmd script to do this at a scheduled time every day using windows scheduled tasks.  
0
Comment
Question by:bayouexpert
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:number1pride
ID: 33562995
you can use xcopy on batch file.
xcoyp /?
0
 

Author Comment

by:bayouexpert
ID: 33563012
Yea, I tried that with the /RS  /RC commands and it didn't work.  It copies the folder but doesn't delete the source.  I need to MOVE the folder so it needs to be gone from the source location
0
 
LVL 7

Expert Comment

by:mquiroz
ID: 33563098
there's a microsoft utility calle robocopy, works like a charm, i use it daily on scheduled task to MIRROR some directories as a backup policy, it updates, deletes an adds as necessary, depending on the OS version you have maybe it's already installed or you'll have to download it from microsoft, once you have it installed in both machines your *.bat file maybe something like this:

robocopy D:\mypath \\172.1.1.5\d$\mypath /E /MIR /NP /R:1 /W:1 > d:\backups\log_backup.txt

ypu can get it from here:

http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 7

Expert Comment

by:mquiroz
ID: 33563131
you'll need to use the following option to delete source once the copy is made:

  /MOV :: MOVe files (delete from source after copying).
 /MOVE :: MOVE files AND dirs (delete from source after copying).


I like a lot this utility 'cause it resumes the copy process as many times is necessary in case there are communication outages or errors.
0
 

Author Comment

by:bayouexpert
ID: 33569795
I"m going to try it with Robocopy right now.  so they command would look like this??

c:\temp z:\backup /MOVE       ???    Would this move the TEMP folder to the backup folder or just move everything within the temp folder to the backup folder???
0
 

Author Comment

by:bayouexpert
ID: 33569967
Problem.  the Target Directory is on a different server.  I can't get it to work in DOS but I downloaded the GUI and it works great.  How can I get the command that the GUI is running so I can put it into a .vbs and schedule it as a scheduled task?
0
 
LVL 14
ID: 33572025
Here this is what you need to run to do:  If you are using Windows 2003 or prior Download and install the GUI on the server where the script will run.

 (If you are running this on Windows 2008/2008r2/vista/ or 7 the Robocopy command is already present by default and includes improved functionality.  So you would NOT want to install the GUI on these systems)

Then you can schedule the command or a batch file with the Robocopy commands if you want to do something complex or just to keep editing the process more simple than using task scheduler.

To run Robocopy from the command line:

RoboCopy "c:\backups" "J:|Temp\Backups" * /MOVE /ZB /E

NOTE: IT IS ALWAYS BETTER TO USE A UNC PATH TO THE SERVER INSTEAD OF A MAPPED DRIVE!  Below is an example of this:

Robocopy "C:\Backups" "\\DellBackup\Share\Temp\Backup" * /MOVE /ZB /E
0
 
LVL 14

Accepted Solution

by:
Ben Personick (Previously QCubed) earned 2000 total points
ID: 33572075
If you want to do the above as part of a batch file, and log the info to a log file located on Drive C:\ of the original server you could use the attached batch file.

Batch files are schedule-able in scheduled task manager, and if you want to do additional operations in SQL you can use the Windows oSQL commands or embed a call to a VBScript you already have if you like.

If you want to do additional steps other than this, you should post a new request detailing the additional steps and I'd be happy to help you accomplish them.  Batch scripting is far more powerful than people give it credit far. =D

-Q


:: Script Name: MoveBackups.bat
ECHO OFF
:: Set Variables Here
SET "SrcDir=C:\Backups"
SET "DstDir=\\DellBackup\Share\Temp\Backup"
SET "LogFile=C:\Move-Backups.log"
:: Run RoboCopy Command Here
RoboCopy "%SrcDir%" "%DstDir%" * /MOVE /ZB /E /LOG:"%LogFile%"

Open in new window

0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

670 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