Author Topic: Batch File to Create 25 backs up then at the 26 remove the first...Circularoty..  (Read 1340 times)

menor59

  • Newbie
  • *
  • Posts: 1
Code: [Select]
:: --- BATCH SCRIPT START ---
:: --- Batch File to Copy and create new folder for AMAG Backup's ---
:: --- Created By: Me ---
@echo off
net use Z: \\smcbackup\amag /PERSISTENT:YES
setlocal enabledelayedexpansion
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set target=Z:\AMAG Backup\GLOBALSRV\%%C-%%B-%%A-AMAG Back Up
xcopy "D:\Program Files\Microsoft Sql Server\MSSQL\Backup\*" "%target%\" /E /-Y
setlocal
set source=Z:\AMAG Backup\GLOBALSRV
pushd "%source%"
FOR /F "skip=25 delims=" %%a IN ('DIR /B /AD 25?????? ^| SORT /R') DO RD /S /Q "%%a"
popd
endlocal
:: --- BATCH SCRIPT END ---

Somethings not working right...I believe its here...
Code: [Select]
FOR /F "skip=25 delims=" %%a IN ('DIR /B /AD 25?????? ^| SORT /R') DO RD /S /Q "%%a"

I need it do do run concurent 25 folders...then at the 26th time it runs it removes the 1st folder to create the 26...the next day to remove the 2nd and create the 27th...Basically a circulatory back up that keeps the newest 25 folders always...

This Batch file runs Daily once a day...

snowsnowsnow

  • Full Member
  • ***
  • Posts: 224
Looks like you're in the wrong place.  This forum is for WinBatch, not for "ordinary" DOS/Windows "batch".

You might try:

news://alt.msdos.batch.nt