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
Solved

copy script to search for source file

Posted on 2014-03-06
4
498 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

838 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