Solved

File Copy CMD

Posted on 2013-01-28
7
659 Views
Last Modified: 2013-02-13
We have a Win 2k8 R2 Domain controller which we are backing up with Windows Server Backup.

The backups run daily to a local drive on the server and what we are looking to do is create a scheduled batch script to copy the backups to a USB flash drive which is offsited on a daily basis.


The backups are saved in the following location

A:\WindowsImageBackup\servername\Backup*Datestamp*\

I want them to be copied to the follwing location

G:\Backup

However I cannot simply run a copy as it will fill the flash drive with backups as it copies the folder structure and not overwrite.

So I am looking for a script which will allow me to take the VHD files from A:\Windowsimagebackup\Servername\ and save them without a folder structure onto G:\backups and consequently overwrite these files each week.

I have tried the following cmds but they seem to copy only one VHD and then freeze:

for /R A:\Windowsimagebackup\servername %f in (*.VHD) do copy "%f" G:\Backup\

and

ROBOCOPY A:\Windowsimagebackup\servername G:\Backup\ *.VHD /E


I appreciate any help and am willing to provide more information if possible.

David
0
Comment
Question by:WVHT
[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
7 Comments
 
LVL 1

Expert Comment

by:ggoodwill
ID: 38826483
If I've understood correctly what you're trying to acheive, then give this a go:

robocopy "A:\Windowsimagebackup\servername" "G:\Backup" /E /V /IT /ZB

It's what we use, although not to copy VHD files.

/E - copy subdirectories, including Empty ones.
/V - produce Verbose output, showing skipped files. (may help pinpoint any issues with copying)
/IT - include tweaked files.
/ZB - use restartable mode; if access denied use Backup mode.

Hope this helps!
0
 

Author Comment

by:WVHT
ID: 38826803
Hi Thank you very much.

This does copy the correct files however is there anyway in copying only the VHD files and also not copying the folder structure.

This is because at present the backups are now saved in the following location:

G:\Backup\Backup 2013-01-28 040006

This time next week we will have the same flash drive in the server and the Robocopy cmd you supplied will create another folder with the backups in rather than overwriting them.

So to try and explain a little further. I have 3 VHD files (amongst others, but its the VHD's we need) saved in the following location:

A:\
     Windowsimagebackup\
                                              servername\
                                                                    *Backup Date*\
                                                                                                abc.vhd
                                                                                                def.vhd
                                                                                                ghi.vhd

and rather than replicate the foler structure I would prefer it to be as follows:

G:\
     Backup\
                    abc.vhd
                    def.vhd
                    ghi.vhd

As the VHD files keep the same name they can be overwritten weekly but the parent folder uses the date of backup as its name which will change and therefore not overwrite the data that is already there causing the flash drive to run out of space.

Regards
0
 
LVL 1

Expert Comment

by:ggoodwill
ID: 38826991
Oh sorry! My mistake, I realise what you mean now.

What about:
robocopy "A:\Windowsimagebackup\servername\*.VHD" "G:\Backup" /E /V /IT /ZB    ?

I've never tried a wildcard like that with robocopy but I see no reason for it not to work.
Obviously this way it will only copy the VHD files and it should only copy the changed VHD(s) over to the flash drive - thus overwriting the VHDs of the same name. You should only ever have the 3 VHD files on the drive this way.
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 85

Expert Comment

by:oBdA
ID: 38827269
You can't use robocopy to flatten folder structures. Try the script below, which gets the latest(!) folder inside "A:\Windowsimagebackup\servername", assuming your backup folder is always the latest one. If you'd rather have it by name (your YYYY-MM-DD format should work for that), replace "/o:d" in line 5 with "/o:n".
The script is currently in test mode and will only display the robocopy command it would normally run, so that you can test it; remove the uppercase ECHO in line 7 to run it for real.
@echo off
setlocal
set SourceFolder=A:\Windowsimagebackup\servername
set TargetFolder=G:\Backup
for /f "delims=" %%a in ('dir /b /a:d /o:d C:\temp\*') do (set LatestDir=%%a)
echo Copying from %LatestDir% ...
ECHO robocopy.exe "%SourceFolder%\%LatestDir%" "%TargetFolder%" *.vhd
echo Done. 

Open in new window

0
 

Author Comment

by:WVHT
ID: 38834373
Hi oBdA

Using your script and modifying it slighttly I have got the copy to partially work. Because there are muliple folder which are created under the Servername directory i have used the /o:s switch on line 5 to choose the largest folder (which coincidentally has the backups in).

When i run the following script it finds that there are 3 .VHD files and begins copying but when it gets to 100% of the first vhd nothing else happens. Attached is the cmd window once it has copied the first .vhd file.

1: @echo off
2: setlocal
3: set SourceFolder=A:\Windowsimagebackup\wvhtpad01
4: set TargetFolder=G:\Backup
5: for /f "delims=" %%a in ('dir /b /a:d /o:s a:\windowsimagebackup\wvhtpad01\backup*') 6: do (set LatestDir=%%a)
7: echo Copying from %LatestDir% ...
8: robocopy.exe "%SourceFolder%\%LatestDir%" "%TargetFolder%" *.vhd
9: Pause
10: echo Done.
0
 

Author Comment

by:WVHT
ID: 38834374
Hi oBdA

Using your script and modifying it slighttly I have got the copy to partially work. Because there are muliple folder which are created under the Servername directory i have used the /o:s switch on line 5 to choose the largest folder (which coincidentally has the backups in).

When i run the following script it finds that there are 3 .VHD files and begins copying but when it gets to 100% of the first vhd nothing else happens. Attached is the cmd window once it has copied the first .vhd file.

1: @echo off
2: setlocal
3: set SourceFolder=A:\Windowsimagebackup\wvhtpad01
4: set TargetFolder=G:\Backup
5: for /f "delims=" %%a in ('dir /b /a:d /o:s a:\windowsimagebackup\wvhtpad01\backup*') 6: do (set LatestDir=%%a)
7: echo Copying from %LatestDir% ...
8: robocopy.exe "%SourceFolder%\%LatestDir%" "%TargetFolder%" *.vhd
9: Pause
10: echo Done.
CopyCMD.jpg
0
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 38834564
Could be that it's still copying, or something went seriously wrong when copying. The copy process might be on 100% while the cache is still being written to the external drive.
Add "/L" to the robocopy options and run the script again; this will just simulate a run without actually copying anything, and should list all vhd files that should be copied.
0

Featured Post

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

696 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