Solved

File Copy CMD

Posted on 2013-01-28
7
641 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

13 Experts available now in Live!

Get 1:1 Help Now