Solved

copy script to search for source file

Posted on 2014-03-06
4
497 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:Allen
  • 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:Allen
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 53

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 AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP/VB email question 4 35
How to remove unwanted words? 34 40
backup program with robocopy 6 22
Selenium docs api java index 3 18
This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

803 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