1.

Solve : Help me on this batch file?

Answer»

I am TRYING to increment a folder over a network for example I created BK1 next will be BK2 for backups of files here is the code, the problem is only increment 1 folder but the next it KEEPS saying folder already exist and skipped all my backups, bellow is my code, what am I missing? please help





@echo off
:: variables
setlocal enableDelayedExpansion
set source1=\\server1\c$\MSSQL7\BACKUP
set source2=\\server2\z$
set desti1=\\pc1\d$\AlimsS\BACKUP
set desti2=\\pc1\d$\AlimsW\BK
set backupcmd=robocopy
REM
REM *********** Backing Alimss
REM
set "lastFolder=0"
for /F "delims=" %%F in (
'2^>nul dir /b /ad "%drive1%*."^|findstr /xri "%desti1%[0-9]*"'
) do (
set "name=%%F"
set "name=!name:*%desti1%=!"
if !name! gtr !lastFolder! set "lastFolder=!name!"
)
set /a nextFolder=lastFolder+1
md "%dest1%%nextFolder%"

%backupcmd% *.* /ZB /A-:SH /E /COPY:DAT "%source1%" "%desti1%%nextfolder%"
REM
REM *********** Backing WEB
REM
set "lastFolder=0"
for /f "delims=" %%F in (
'2^>nul dir /b /ad "%desti2%*."^|findstr /xri /c:"%desti2%[0-9]*"'
) do (
set "name=%%F"
set "name=!name:*%desti2%=!"
if !name! gtr !lastFolder! set "lastFolder=!name!"
)
set /a lastfolder=nextfolder+1
mkdir "%desti2%%nextFolder%"
%backupcmd% *.* /ZB /A-:SH /E /COPY:DAT "%source2%" "%desti2%%nextfolder%"
@pause
@echo on

[­code]Code Tags[­/code]I don't see the %drive1% variable ever get defined anywhere.
Would help to see what your folder names actually LOOKED like as well.Quote from: Squashman on April 10, 2014, 06:35:52 PM

I don't see the %drive1% variable ever get defined anywhere.
Would help to see what your folder names actually looked like as well.



sorry that should be %desti1% and still doest work...

on the %desti1% it should add a folder Backup1 and when I run buckup the next day I will write Backup2 and so on, I will have a backup for every day still not done with the code but I will add to delete backup of X days old but I need to fix this problem first...
please help me solve this issueDo you realize that batch does not sort in numeric order. If you have 10 backups and run the dir command your output will look like this.
Code: [Select]Backup1
Backup10
Backup2
Backup3
etc......Personally I think you should name your backups by date in a YYYYMMDD format.
That way you don't have to screw around with figuring out your last backup number.


Discussion

No Comment Found