Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

File Copy CMD

Posted on 2013-01-28
7
Medium Priority
?
689 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
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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