home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch      Fun with MS-DOS batch files      42,547 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 41,015 of 42,547   
   Todd Vargo to justin.lamantia@gmail.com   
   Re: Batch File to Create 25 backs up the   
   19 Sep 14 21:41:10   
   
   From: tlvargo@sbcglobal.netz   
      
   On 9/18/2014 12:11 PM, justin.lamantia@gmail.com wrote:   
   > [code]   
   > :: --- 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 ---   
   > [/code]   
   >   
   > Somethings not working right...I believe its here...   
   > [code]   
   > FOR /F "skip=25 delims=" %%a IN ('DIR /B /AD 25?????? ^| SORT /R') DO RD /S   
   /Q "%%a"   
   > [/code]   
   >   
   > 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...   
      
   You are correct. As foxi indicates, you should add /O-D to sort by date   
   in reverse order and eliminate the "^| SORT /R" part. Also, since you   
   are creating your backups by year, your "25??????" will not match   
   anything. Helloooo... Its 2014 not 2514. So it should be "20*".   
      
   Try this line instead.   
      
   FOR /F "skip=25 delims=" %%a IN ('DIR/B/AD/O-D 20*') DO RD /S /Q "%%a"   
      
   FWIW, one of my personal peeves is changing to another folder just to   
   shorten the command line where deleting files or folders is involved. I   
   am an advocate of not taking shortcuts where deleting is concerned. In   
   your case, it would be easy enough to insert %source% in the DIR and RD   
   commands to eliminate the PUSHD as shown below.   
      
   FOR /F "skip=25 delims=" %%a IN ('DIR/B/AD/O-D "%source%\20*"') DO RD /S   
   /Q "%source%\%%a"   
      
   HTH   
      
   --   
   Todd Vargo   
   (Post questions to group only. Remove "z" to email personal messages)   
      
   --   
   Todd Vargo   
   (Post questions to group only. Remove "z" to email personal messages)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca