Solved

copy script to search for source file

Posted on 2014-03-06
4
491 Views
Last Modified: 2014-03-07
I'm trying to copy a Windows backup file (VHD) to a Samba share that is backed up off site weekly.  However- I need to only backup the VHD (not the XML files, directories, etc.) and place the VHD in the root of the share.  I can of course do this manually, but would like to instead schedule a script to run weekly.

The hard part is getting my script to search the WindowsImageBackup\...\ directories for the VHD files before copying.  Is there a copy tool, such as xcopy, that will search subdirectories for the source file, or does anyone have a handy dandy script?
0
Comment
Question by:AWOOD-HILL
  • 2
4 Comments
 
LVL 13

Assisted Solution

by:Santosh Gupta
Santosh Gupta earned 100 total points
ID: 39911082
Try this

forfiles /p  "D:\" /s /m *.vhd  /c "cmd /c copy @file E:\backup"
0
 

Author Comment

by:AWOOD-HILL
ID: 39911100
Thanks for the response.  

I received- ERROR: Invalid argument/option - '@file'

D:\ is the source & E:\backup is the destination, correct?
0
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39911121
Note: do not use '\' after source and destination name. like C:\temp NOT C:\temp\

yes, D:\ is the source & E:\backup is the destination.
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 200 total points
ID: 39911294
Here's a small BAT script that should do the job, it uses the DIR command to find all VHD files under the base folder you specify, including subfolders, and then processes that list copying each file to the destination backup location.

Save as a BAT file and adjust the SET lines near the top as needed.

@echo off
setlocal

set BaseDir=C:\WindowsImageBackup
set DestDir=Z:\Backup

for /f "tokens=*" %%A in ('dir /b /s /a-d "%BaseDir%\*.vhd"') do (
  copy "%%~A" "%DestDir%"
)

Open in new window

~bp
0

Featured Post

Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

706 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

18 Experts available now in Live!

Get 1:1 Help Now