?
Solved

File Copy CMD

Posted on 2013-01-28
7
Medium Priority
?
699 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

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 86

Accepted Solution

by:
oBdA earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses

616 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