Solved

File Copy CMD

Posted on 2013-01-28
7
650 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 83

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 83

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now