Jump to content

Question regarding advanced "for" use in batch file


Recommended Posts

In a console window, run the following three lines and then take a look at the content of _OUT_PUT.LOG.

PUSHD C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy
@FOR /d /r %# IN (*) DO @ECHO=%~nx#>>_OUT_PUT.LOG
POPD

Does the log file provide you with every directory name located below your structure? and is that not what you asked for?

Link to comment
Share on other sites


I tried both versions but the "!" instead of the "%" didnt work.

You evidently did not run the posted batch, which provides for enabling delayed expansion (and sets ECHO to OFF, so that you CANNOT have anyway that output).

You tried to modify it (badly :whistle: ).

See why delayed expansion is needed in that script:

http://www.robvanderwoude.com/variableexpansion.php

Simply:

  1. make a folder: C:\test\
  2. copy in in it the two given lines WITHOUT changes as C:\test\list.txt
  3. copy in it the little batch WITHOUT changes naming it C:\test\test.cmd

Now, open a command prompt, navjgate to C:\test, then issue:

test.cmd

[ENTER]

What is the output ?

On my machine it is:

C:\test>test
robocopy "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\vol_9edf29cf-c89
a-4fe5-97d6-7c9ce70c13b0" "U:\DPM\vol_9edf29cf-c89a-4fe5-97d6-7c9ce70c13b0" /E /
ZB /MIR /XD "System Volume Information" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m
4*" /LOG+:"" /TEE /NP

(and it will be EXACTLY the same on yours)

General idea:

  • do things EXACTLY as they are suggested, WITHOUT introducing ANY changes, of ANY type, first. ;), once it works, THEN start making changes to it for experiment

jaclaz

Link to comment
Share on other sites

Hi guys !

Yzöwl:

Yeah, I got a list with all directory names below C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy. That worked.

Is there a simple way to only scan like 5 directories below C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy ? That would probably work and not create a list of thousands of directories :)

Jaclaz:

Sorry, I did incorporate your script into my larger script and changed a bit but not much. Must have screwed something up, you are right :whistle:

It works now even with two or more lines in list.txt

Sorry for being such a newbie :blushing:

Alex

Link to comment
Share on other sites

Yzöwl:

Yeah, I got a list with all directory names below C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy. That worked.

Since the code I provided uses those lines it scans, as you requested, every single directory below your given path and checks each directory name against that listed in your listfile.

Are you sure that you didn't actually change something other than the two lines containing variables you hadn't provided me with? (shadowcopieslist.txt, and your USB drive letter)

Link to comment
Share on other sites

Hi Yzöwl,

ok I tried your script without any changes now (except for adding a pause command + changing the branch variable to a subdirectory to limit the output. Here is the script i used:


rem @ECHO off
SETLOCAL enableextensions disabledelayedexpansion

REM Set the two variables below
SET "LISTOF=D:\Scripts\USB_Backup\shadowcopieslist.txt"
SET "USB=G:"

SET "BRANCH=C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer"
(SET RCOPTS=/E /ZB /MIR)
(SET RCOPTS=%RCOPTS% /XD "System Volume Information")
(SET RCOPTS=%RCOPTS% /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*")
(SET RCOPTS=%RCOPTS% /LOG+:"%LOG%" /TEE /NP)

SET "DESTIS=%USB%\DPM"

PUSHD %BRANCH%
FOR /d /r %%# IN (*) DO (
ECHO=%%~nx# | FINDSTR/ixg:"%LISTOF%" >NUL 2>&1 && (CALL :CopyIt %%#)
)

pause
POPD

:CopyIt
ROBOCOPY "%*" "%DESTIS%" %RCOPTS%

This is the shadowcopieslist.txt file:


vol_1c79e280-ba21-484f-8f3d-82a4f4419872

Thats the first subdirectory in the branch.

This is the output:


D:\Scripts\USB_Backup>rem @ECHO off

D:\Scripts\USB_Backup>SETLOCAL enableextensions disabledelayedexpansion

D:\Scripts\USB_Backup>REM Set the two variables below

D:\Scripts\USB_Backup>SET "LISTOF=D:\Scripts\USB_Backup\shadowcopieslist.txt"

D:\Scripts\USB_Backup>SET "USB=G:"

D:\Scripts\USB_Backup>SET "BRANCH=C:\Program Files\Microsoft DPM\DPM\Volumes\Sha
dowCopy\Non VSS Datasource Writer"

D:\Scripts\USB_Backup>(SET RCOPTS=/E /ZB /MIR )

D:\Scripts\USB_Backup>(SET RCOPTS=/E /ZB /MIR /XD "System Volume Information" )


D:\Scripts\USB_Backup>(SET RCOPTS=/E /ZB /MIR /XD "System Volume Information" /X
F "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" )

D:\Scripts\USB_Backup>(SET RCOPTS=/E /ZB /MIR /XD "System Volume Information" /X
F "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:"" /TEE /NP )

D:\Scripts\USB_Backup>SET "DESTIS=G:\DPM"

D:\Scripts\USB_Backup>PUSHD C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCop
y\Non VSS Datasource Writer

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
FOR / %# IN (*) DO (ECHO=%~nx# | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopi
eslist.txt" 1>NUL 2>&1 && (CALL :CopyIt %# ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=vol_1c79e280-ba21-484f-8f3d-82a4f4419872 | FINDSTR/ixg:"D:\Scripts\USB_B
ackup\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Micr
osoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484
f-8f3d-82a4f4419872 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=vol_2e4dcc92-a087-4319-8977-ec16e1cb78d2 | FINDSTR/ixg:"D:\Scripts\USB_B
ackup\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Micr
osoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_2e4dcc92-a087-431
9-8977-ec16e1cb78d2 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=vol_39cd1c45-4cfc-4876-942a-f23b65414048 | FINDSTR/ixg:"D:\Scripts\USB_B
ackup\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Micr
osoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_39cd1c45-4cfc-487
6-942a-f23b65414048 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=vol_8e6cc792-07cc-4767-9c24-582ab86458f8 | FINDSTR/ixg:"D:\Scripts\USB_B
ackup\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Micr
osoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_8e6cc792-07cc-476
7-9c24-582ab86458f8 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=vol_a48a61d2-b2e9-423a-83fd-0441961bef98 | FINDSTR/ixg:"D:\Scripts\USB_B
ackup\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Micr
osoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_a48a61d2-b2e9-423
a-83fd-0441961bef98 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=vol_e7e4933b-574d-4f20-8e6e-5c67d6b0601a | FINDSTR/ixg:"D:\Scripts\USB_B
ackup\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Micr
osoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_e7e4933b-574d-4f2
0-8e6e-5c67d6b0601a ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=68be349c-090c-4392-8e80-fdaeb100eddd | FINDSTR/ixg:"D:\Scripts\USB_Backu
p\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsof
t DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f
3d-82a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Full | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non
VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419872\68be349c-090c-43
92-8e80-fdaeb100eddd\Full ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=F-Vol | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\No
n VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419872\68be349c-090c-4
392-8e80-fdaeb100eddd\Full\F-Vol ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=WindowsImageBackup | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist
.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\
ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419872\68
be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=SECDOM | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NU
L 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\N
on VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419872\68be349c-090c-
4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Backup 2011-08-27 120048 | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopi
eslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Vo
lumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419
872\68be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM\Ba
ckup 2011-08-27 120048 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Catalog | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>N
UL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\
Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419872\68be349c-090c
-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM\Catalog ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=SPPMetadataCache | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.t
xt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\Sh
adowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419872\68be
349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM\SPPMetadat
aCache ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=1dd4f965-cb2a-42fc-8fc6-871e60804c31 | FINDSTR/ixg:"D:\Scripts\USB_Backu
p\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsof
t DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_2e4dcc92-a087-4319-89
77-ec16e1cb78d2\1dd4f965-cb2a-42fc-8fc6-871e60804c31 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Full | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non
VSS Datasource Writer\vol_2e4dcc92-a087-4319-8977-ec16e1cb78d2\1dd4f965-cb2a-42
fc-8fc6-871e60804c31\Full ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=C-Vol | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\No
n VSS Datasource Writer\vol_2e4dcc92-a087-4319-8977-ec16e1cb78d2\1dd4f965-cb2a-4
2fc-8fc6-871e60804c31\Full\C-Vol ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=DPM_SYSTEM_STATE | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.t
xt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\Sh
adowCopy\Non VSS Datasource Writer\vol_2e4dcc92-a087-4319-8977-ec16e1cb78d2\1dd4
f965-cb2a-42fc-8fc6-871e60804c31\Full\C-Vol\DPM_SYSTEM_STATE ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=a9680f68-29a5-42d8-bd65-ed720b09d386 | FINDSTR/ixg:"D:\Scripts\USB_Backu
p\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsof
t DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_39cd1c45-4cfc-4876-94
2a-f23b65414048\a9680f68-29a5-42d8-bd65-ed720b09d386 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Full | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non
VSS Datasource Writer\vol_39cd1c45-4cfc-4876-942a-f23b65414048\a9680f68-29a5-42
d8-bd65-ed720b09d386\Full ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=C-Vol | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\No
n VSS Datasource Writer\vol_39cd1c45-4cfc-4876-942a-f23b65414048\a9680f68-29a5-4
2d8-bd65-ed720b09d386\Full\C-Vol ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=WindowsImageBackup | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist
.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\
ShadowCopy\Non VSS Datasource Writer\vol_39cd1c45-4cfc-4876-942a-f23b65414048\a9
680f68-29a5-42d8-bd65-ed720b09d386\Full\C-Vol\WindowsImageBackup ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=e73426d4-8e7e-4248-8855-15b159d8c931 | FINDSTR/ixg:"D:\Scripts\USB_Backu
p\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsof
t DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_8e6cc792-07cc-4767-9c
24-582ab86458f8\e73426d4-8e7e-4248-8855-15b159d8c931 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Full | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non
VSS Datasource Writer\vol_8e6cc792-07cc-4767-9c24-582ab86458f8\e73426d4-8e7e-42
48-8855-15b159d8c931\Full ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=C-Vol | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\No
n VSS Datasource Writer\vol_8e6cc792-07cc-4767-9c24-582ab86458f8\e73426d4-8e7e-4
248-8855-15b159d8c931\Full\C-Vol ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=WindowsImageBackup | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist
.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\
ShadowCopy\Non VSS Datasource Writer\vol_8e6cc792-07cc-4767-9c24-582ab86458f8\e7
3426d4-8e7e-4248-8855-15b159d8c931\Full\C-Vol\WindowsImageBackup ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=154a5fb4-8aaf-4361-8520-c4a3db71a4a4 | FINDSTR/ixg:"D:\Scripts\USB_Backu
p\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsof
t DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_a48a61d2-b2e9-423a-83
fd-0441961bef98\154a5fb4-8aaf-4361-8520-c4a3db71a4a4 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Full | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non
VSS Datasource Writer\vol_a48a61d2-b2e9-423a-83fd-0441961bef98\154a5fb4-8aaf-43
61-8520-c4a3db71a4a4\Full ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=C-Vol | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\No
n VSS Datasource Writer\vol_a48a61d2-b2e9-423a-83fd-0441961bef98\154a5fb4-8aaf-4
361-8520-c4a3db71a4a4\Full\C-Vol ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=WindowsImageBackup | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist
.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\
ShadowCopy\Non VSS Datasource Writer\vol_a48a61d2-b2e9-423a-83fd-0441961bef98\15
4a5fb4-8aaf-4361-8520-c4a3db71a4a4\Full\C-Vol\WindowsImageBackup ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=55e1330c-8a3d-43b4-b305-bbad5253403f | FINDSTR/ixg:"D:\Scripts\USB_Backu
p\shadowcopieslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsof
t DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e
6e-5c67d6b0601a\55e1330c-8a3d-43b4-b305-bbad5253403f ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Full | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non
VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e6e-5c67d6b0601a\55e1330c-8a3d-43
b4-b305-bbad5253403f\Full ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=D-Vol | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>NUL
2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\No
n VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e6e-5c67d6b0601a\55e1330c-8a3d-4
3b4-b305-bbad5253403f\Full\D-Vol ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=WindowsImageBackup | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist
.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\
ShadowCopy\Non VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e6e-5c67d6b0601a\55
e1330c-8a3d-43b4-b305-bbad5253403f\Full\D-Vol\WindowsImageBackup ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=dpm2010 | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>N
UL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\
Non VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e6e-5c67d6b0601a\55e1330c-8a3d
-43b4-b305-bbad5253403f\Full\D-Vol\WindowsImageBackup\dpm2010 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Backup 2011-08-27 032131 | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopi
eslist.txt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Vo
lumes\ShadowCopy\Non VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e6e-5c67d6b06
01a\55e1330c-8a3d-43b4-b305-bbad5253403f\Full\D-Vol\WindowsImageBackup\dpm2010\B
ackup 2011-08-27 032131 ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=Catalog | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.txt" 1>N
UL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\
Non VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e6e-5c67d6b0601a\55e1330c-8a3d
-43b4-b305-bbad5253403f\Full\D-Vol\WindowsImageBackup\dpm2010\Catalog ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
(ECHO=SPPMetadataCache | FINDSTR/ixg:"D:\Scripts\USB_Backup\shadowcopieslist.t
xt" 1>NUL 2>&1 && (CALL :CopyIt C:\Program Files\Microsoft DPM\DPM\Volumes\Sh
adowCopy\Non VSS Datasource Writer\vol_e7e4933b-574d-4f20-8e6e-5c67d6b0601a\55e1
330c-8a3d-43b4-b305-bbad5253403f\Full\D-Vol\WindowsImageBackup\dpm2010\SPPMetada
taCache ) )

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer>
pause
Press any key to continue . . .

The first command should have copied the conten of this subdirectory:

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82a4f4419872

But it didnt.

Also this line will cause a problem I think:


ROBOCOPY "%*" "%DESTIS%" %RCOPTS%

Because the /MIR switch in robocopy will cause everything in the destination to be deleted that does not exist in the source. So I think we will have to copy each source into a seperate subdirectory of %DESTIS%.

Again, lots of thanks for your help on this !

Have a nice Sunday Yzöwl !

Alex

Link to comment
Share on other sites

Due to the fact you appear to have a large tree structure I've decided to change the script instead of 'fixing' the previous one:

@ECHO Off
SETLOCAL EnableExtensions DisableDelayedExpansion

SET "LISTOF=D:\Scripts\USB_Backup\shadowcopieslist.txt"
SET "USB=G:"
SET "BRANCH=C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy"
SET "BRANCH=%BRANCH%\Non VSS Datasource Writer"
(SET RCOPTS=/E /ZB /MIR)
(SET RCOPTS=%RCOPTS% /XD "System Volume Information")
(SET RCOPTS=%RCOPTS% /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*")
(SET RCOPTS=%RCOPTS% /LOG+:"%LOG%" /TEE /NP)
SET "DESTIS=%USB%\DPM"

FOR /f "UseBackQ Tokens=*" %%# IN ("%LISTOF%") DO (
FOR /f "Tokens=*" %%$ IN ('DIR/B/S/AD "%BRANCH%\%%#"2^>Nul') DO (
CALL :CopyIt %%$
)
)
PAUSE
GOTO :Eof

:CopyIt
ECHO=ROBOCOPY "%*" "%DESTIS%" %RCOPTS%

I have not changed anything with your Robocopy command, I'll leave that to you!

Link to comment
Share on other sites

Hi Yzöwl,

unfortunately it does not work really. This is the output I get with the new version:


ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\$RECYCLE.BIN" "G:\DPM" /E /ZB /MIR /XD "System Volume Information" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*
" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd" "G:\DPM" /E /ZB /MIR /XD "System Volume Information" /XF "*.mp*" "*.avi
" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\System Volume Information" "G:\DPM" /E /ZB /MIR /XD "System Volume Information" /XF "*.mp*" "*.avi" "*.mkv" "
*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\$RECYCLE.BIN\S-1-5-21-654489264-3419089459-3909593113-1113" "G:\DPM" /E /ZB /MIR /XD "System Volume Informati
on" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd\Full" "G:\DPM" /E /ZB /MIR /XD "System Volume Information" /XF "*.mp*" "
*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol" "G:\DPM" /E /ZB /MIR /XD "System Volume Information" /XF "*.
mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup" "G:\DPM" /E /ZB /MIR /XD "System Volume I
nformation" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM" "G:\DPM" /E /ZB /MIR /XD "System V
olume Information" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM\Backup 2011-08-27 120048" "G:\DPM"
/E /ZB /MIR /XD "System Volume Information" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /N
P
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM\Catalog" "G:\DPM" /E /ZB /MIR /XD "
System Volume Information" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
ROBOCOPY "C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Non VSS Datasource Writer\vol_1c79e280-ba21-484f-8f3d-82
a4f4419872\68be349c-090c-4392-8e80-fdaeb100eddd\Full\F-Vol\WindowsImageBackup\SECDOM\SPPMetadataCache" "G:\DPM" /E /ZB /
MIR /XD "System Volume Information" /XF "*.mp*" "*.avi" "*.mkv" "*.wm*" "*.m4*" /LOG+:""G:\copylog.txt"" /TEE /NP
Press any key to continue . . .

It seems like robocopy tries to copy every subdirectory inside the directory that shall be copied extra instead of just the directoy whose name is mentioned in the listfile.

Anyway ... I am using jaclaz´ version now, it works great and I can understand the script. It is not as refined maybe because I have to add all the full paths I need to copy into the list file instead of just the directory name but it works fine.

I really thank all of you guys especially Yzöwl and Jaclaz for spending time to help me and making me understand this ;)

I am so grateful !

Alex

Link to comment
Share on other sites

Hey bphlpt !

Of course I can post it, I am posting the whole script now, not only the part which copies the files, but also the parts that creates snapshots in DPM etc.

Maybe someone who also uses DPM can make good use of it !



@ECHO OFF
cd /D %~dp0



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Script needs blat downloaded (http://tinyurl.com/2qdxea) and setup to mail to the local server. Put blat.exe into this folder.
REM Script needs wget.exe + libeay32.dll +libiconv2.dll +libintl3.dll +libssl32.dll in this folder (for FTP part)
REM Script needs shadowcopieslist.txt file containing directories to be copied to USB in Phase 4
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::




::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM CHECK FOR IDENTITY FILE ON ALL DRIVES ATTACHED TO THE COMPUTER AND QUIT SCRIPT IF NO DRIVE IS ATTACHED
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



For /f %%# In ('Mountvol^|Findstr [c-z]:\\') Do If Exist %%#IphosUSBbackup (Set USB=%%~d#)
if not defined USB goto NOUSB



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM SET VARIABLES
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



set p=%~dp0
set log="%USB%\copylog.txt"
set roboparametermirror=/E /ZB /MIR /XD "System Volume Information" /XF "*.mp*" "*.avi" "*.flv" "*.mkv" "*.wm*" "*.m4*" /R:20 /LOG+:"%LOG%" /NP /TEE
set mailadress=
set company=
set server=%hostname%
set smtpserver=
set fromadress=administrator@dpm2010.iphos.local
set subject=Windows USB Backup Jobs Completed
SET LISTOFSHADOWCOPIES=%p%shadowcopieslist.txt



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM CHECK FOR OLD DATE IDENTIFIER AND DELETE IT
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



if exist "%USB%\Created_*" del "%USB%\Created_*"
if exist "%log%" del "%log%"



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Configure blat.exe + Start logfile
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



"%p%blat.exe" -install %smtpserver% %fromadress%



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM START LOGFILE ON USB DRIVE
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



ECHO Start Time of script >%log%
date /t >>%log%
time /t >>%log%



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM START FTP TRANSFER TO COPY SVN REPOSITORY ON SVN SERVER TO USB DRIVE
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



ECHO. >>%log%
ECHO PHASE1 ... Downloading SVN Data via FTP ... >>%log%
ECHO. >>%log%



if not exist "%USB%\SVN" md "%USB%\SVN"
wget -a %log% -nv --ftp-user=usbbackup --ftp-password=*********** -m ftp://svn.server.local/ -P "%USB%\SVN"



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM CREATE SHADOW COPIES OF DPM DATA
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



ECHO. >>%log%
ECHO PHASE2 ... Creating Shadow Copies of all DPM Replica Data ... >>%log%
ECHO. >>%log%



"%PROGRAMFILES%\Microsoft DPM\DPM\bin\DpmBackup.exe" -replicas >>%log%



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM DPM DB Backup ERSTELLEN
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



ECHO. >>%log%
ECHO PHASE3 ... Creating Copy of DPM Database ... >>%log%
ECHO. >>%log%



"%PROGRAMFILES%\Microsoft DPM\DPM\bin\DpmBackup.exe" -db >>%log%



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM COPY SOME SHADOW COPIES CREATED IN PHASE2 TO USB DRIVE (Only shadowcopies mentioned in shadowcopieslist.txt)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



ECHO. >>%log%
ECHO PHASE4 ... Copy a few important Shadow Copies from DPM Mountpoints to USB drive ... >>%log%
ECHO .......... If you want to change selection change shadowcopieslist.txt .... >>%log%
ECHO. >>%log%



SETLOCAL ENABLEDELAYEDEXPANSION
if not exist "%USB%\DPM" md "%USB%\DPM"
FOR /F "skip=1 tokens=* delims=" %%A IN (%LISTOFSHADOWCOPIES%) DO (
SET DPMSource=%%A
SET DPMName=%%~nA
robocopy "!DPMSource!" "%USB%\DPM\!DPMname!" %roboparametermirror%
)



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM TAG THE USB DRIVE WITH CURRENT DATE
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



echo BACKUP CREATION DATE > "%USB%\Created_%date%"



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM SEND EMAIL WITH LOG TO ADMINS AND EXIT SCRIPT
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



"%p%blat.exe" %log% -to %mailadress% -subject "%company% %server% %subject%"
exit



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::



:NOUSB

set mailadress=i
set company=
set server=%hostname%
set smtpserver=
set fromadress=administrator@dpm2010.iphos.local
set subject=ALERT! USB Copy Backup Job FAILED!
set body=No USB Drive configured for USB Backup is attached to %hostname%. Please insert drive or check for correct identifier (IphosUSBbackup) in the root of the drive.

"%p%blat.exe" -install %smtpserver% %fromadress%
"%p%blat.exe" -body "%body%" -to %mailadress% -subject "%company% %server% %subject%"

exit



::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

The shadowcopylist.txt consists of directories on the DPM server:


:: This is a list of directories that will be copied to USB drive by the FOR /F LOOP Robocopy command in backup_to_usb.cmd

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\Database Backups
C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\File System\vol_6a61d272-a115-4d0b-aa59-3e601d21b6a4
etc

Link to comment
Share on other sites

It seems like robocopy tries to copy every subdirectory inside the directory that shall be copied extra instead of just the directoy whose name is mentioned in the listfile.

It seems to me what you asked originally :unsure: Most probably there was an initial misunderstanding.

Anyway ... I am using jaclaz´ version now, it works great and I can understand the script. It is not as refined maybe because I have to add all the full paths I need to copy into the list file instead of just the directory name but it works fine.

Hmmmm.

It seems like you have a common path:

C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\

It shouldn't be that difficult to:

:: This is a list of directories that will be copied to USB drive by the FOR /F LOOP Robocopy command in backup_to_usb.cmd

Common_Path=C:\Program Files\Microsoft DPM\DPM\Volumes\ShadowCopy\

::Following are the directories in it

Database Backups

vol_6a61d272-a115-4d0b-aa59-3e601d21b6a4

SETLOCAL ENABLEDELAYEDEXPANSION

if not exist "%USB%\DPM" md "%USB%\DPM"

FOR /F "tokens=* delims=" %%A IN ('TYPE %LISTOFSHADOWCOPIES% ^| FIND "Common_Path="') DO SET %%A

FOR /F "skip=3 tokens=* delims=" %%A IN (%LISTOFSHADOWCOPIES%) DO (

SET DPMSource=%%A

SET DPMName=%%~nA

robocopy "%Common_Path%!DPMSource!" "%USB%\DPM\!DPMname!" %roboparametermirror%

)

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...