[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

BATCH FILE EXPERT NEEDED!

Scenario: 2 servers- SERV1 & SERV2. SERV1 is the master or template server. The D: drive on SERV1 has 3 directories named BLUE, GREEN, & RED. Inside these 3 directories there are dozens of other files.

GOAL: To create a batch file that when run on SERV2 will create the 3 directories(BLUE, GREEN & RED) and then copy the contents of those 3 directories to the newly created BLUE, GREEN & RED on SERV2 via UNC paths, copy commands or whatever else. In the end , if the batch file works properly it will duplicate the contents of the D: drive onto SERV2. It is safe to assume the D: drive has been sized and partitioned before this batch file is run.

I need the actual commands that a pro would use line by line.
0
Brian_Blair
Asked:
Brian_Blair
  • 4
  • 2
2 Solutions
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
If NOT Exists "d:\blue" mkdir "blue" "green" "red"
copy "\\serv1\sharename\blue\*.*" "d:\blue"
copy "\\serv1\sharename\green\*.*" "d:\green"
copy "\\serv1\sharename\red\*.*" "d:\red"



The above should do it... but there are more questions.  Do these folders have sub folders?  If so, you'll probably want to use XCOPY or ROBOCOPY.  Do these files have security that needs to be copied?
0
 
Brian_BlairAuthor Commented:
YES- there are definately sub folders. Never really thought about the security but in a perfect scenario, yes the security would be copied.
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
If NOT Exists "d:\blue" mkdir "blue" "green" "red"
xcopy "\\serv1\sharename\blue\*.*" "d:\blue" /o /h /e /v /c
xcopy "\\serv1\sharename\green\*.*" "d:\green" /o /h /e /v /c
xcopy "\\serv1\sharename\red\*.*" "d:\red" /o /h /e /v /c

/e = copies folders and subfolders, even empty ones
/o = copies file ownership and security info
/h = copies hidden and system files
/c = continues copying on errors
/v = verifies each file.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Brian_BlairAuthor Commented:
leew- Thanks for the help. At the top of the file do I need any "cls" statements or "cd" change directory statements? Also, in some of your text you have "quotation" marks. Is this the correct syntax?

Get back to me on this and the points are yours.
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
cls only clears the screen.  You can if you like..  Really doesn't have any relevence to the script other than starting on a blank screen.  TECHNICALLY, you don't need the quotes if those are really the folder/file names you are using.  But they don't hurt.  I included them in case you want to modify this and use folder names with spaces.  When you reference shares/folder names with spaces, you get  errors if they are not in quotes.

No need to CD anywhere, all the paths given are absolute.  Other than perhaps opening a command prompt and CD'ing to the folder you have the script in.  But that can be remedied by put a shortcut on your desktop to wherever you save it.

Also, if you want to log this to save the results of the copy process, you can do the following.

1.  Save the script as - for example: COPIER.CMD
2.  From a command prompt, type COPIER > %temp%\COPIER.LOG

#2 creates a file in your temp folder that has ALL output from the command.  You can review it after the command completes and verify that ALL files were copied and see which - if any - had errors.

If the log is unimportant to you, you would simply type "COPIER"
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
One more note - to create a log that records errors, I made a mistake - you should use:

COPIER > %temp%\COPIER.LOG 2>&1

Otherwise, some programs might not save the errors to the log file.
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now