Computing.Net > Forums > Programming > deleting old backups

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

deleting old backups

Reply to Message Icon

Name: meetyourmatch
Date: November 7, 2005 at 05:49:14 Pacific
OS: server 2003
CPU/Ram: 2gb
Comment:

Hi all,
I have a sql database, each night i have a batch file run to back this up to a specified folder; C:\Program Files\Microsoft SQL Server\MSSQL$SIMS\BACKUP
This backup is a zip file.
I now have the problem that i have to manually delete old backups. Does anyone have any ideas of how to write a batch file that will delete backups from over 3 weeks ago from that specified folder?
I'm quite stumped.

Kind Regards
Steve



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 7, 2005 at 06:21:30 Pacific
Reply:

Hi,

Here we go again with "date math"; not easy.

If you can live with keeping the most recent, let's say 3, ZIPs, I've got a script you can use.


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: meetyourmatch
Date: November 7, 2005 at 07:28:15 Pacific
Reply:

Thanks for replying,
Would be most greatfull for a script. Is it possible to keep the last 14?- if not, 3 is good.
Thank you.

Kind Regards
Steve


0

Response Number 3
Name: Mechanix2Go
Date: November 7, 2005 at 09:08:13 Pacific
Reply:

This should do it.

You will need to change the second line to accomodate your directory. I used test.
Sine yours has spaces in it, enclose it in double quotes.

pushd "C:\Program Files\Microsoft SQL Server\MSSQL$SIMS\BACKUP"

:: keep14z.bat
@echo off
pushd test

:loop

dir /b/od *.zip > %TEMP%\templist
set /p file2del=<%TEMP%\templist
call :deleter %file2del%
popd
goto :eof

:deleter

dir /a-d *.zip |find "File(s)">%TEMP%\#
for /f "tokens=1" %%T in (%TEMP%\#) do if %%T LEQ 14 goto :eof
del %1
goto :loop

:eof
:: DONE



If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: meetyourmatch
Date: November 10, 2005 at 01:43:04 Pacific
Reply:

Thank you for that.
Unfortunatly though it will not work. it comes up saying that the specified path cannot be found?? yet the path in there is correct!?!? Any ideas why this would be?
Thank you for your time.

Kind Regards
Steve


0

Response Number 5
Name: Mechanix2Go
Date: November 10, 2005 at 01:53:04 Pacific
Reply:

Post the script which you are using.


If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: meetyourmatch
Date: November 10, 2005 at 02:19:59 Pacific
Reply:

It is exactly the same as what you sent me. The machine i am testing on has all of the sql data on the c:\

pushd C:\Program Files\Microsoft SQL Server\MSSQL$SIMS\BACKUP

:: keep14z.bat
@echo off
pushd test

:loop

dir /b/od *.zip > %TEMP%\templist
set /p file2del=<%TEMP%\templist
call :deleter %file2del%
popd
goto :eof

:deleter

dir /a-d *.zip |find "File(s)">%TEMP%\#
for /f "tokens=1" %%T in (%TEMP%\#) do if %%T LEQ 14 goto :eof
del %1
goto :loop

:eof
:: DONE

Forgive my ignorance, this is the first time i've tried scripting!

Kind Regards
Steve


0

Response Number 7
Name: Mechanix2Go
Date: November 10, 2005 at 02:58:11 Pacific
Reply:

Carefully re-read #3.

You need to REPLACE the second line in my script.

And you need your path enclosed in double quotes.

##################
:: keep14z2.bat
@echo off
pushd "C:\Program Files\Microsoft SQL Server\MSSQL$SIMS\BACKUP"

:loop

dir /b/od *.zip > %TEMP%\templist
set /p file2del=<%TEMP%\templist
call :deleter %file2del%
popd
goto :eof

:deleter

dir /a-d *.zip |find "File(s)">%TEMP%\#
for /f "tokens=1" %%T in (%TEMP%\#) do if %%T LEQ 14 goto :eof
del %1
goto :loop

:eof
:: DONE


If at first you don't succeed, you're about average.

M2


0

Response Number 8
Name: meetyourmatch
Date: November 10, 2005 at 05:33:57 Pacific
Reply:

right, it is now accepting the script, thanks- sorry-i didnt read your previous entry correctly.
When the file runs it loops saying;
Could not find path C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL$SIMS\BACKUP\copy.
i have checked the path and it is definately correct apart from that "\copy" is on the end-does it think that the \copy is part of the file path?
Any ideas?
Thank you

Kind Regards
Steve


0

Response Number 9
Name: Mechanix2Go
Date: November 10, 2005 at 05:40:13 Pacific
Reply:

How did \copy get involved in this?


If at first you don't succeed, you're about average.

M2


0

Response Number 10
Name: monish_career
Date: November 11, 2005 at 01:21:28 Pacific
Reply:

its not accepting certain filenames while deleting can u help me out in this matter.
i want a similiar script for that which deletes the files which are old by more than 3.

hi all this is ur friend


0

Response Number 11
Name: Mechanix2Go
Date: November 11, 2005 at 02:29:25 Pacific
Reply:

Hi monish,

Are you a different person, or the originator with a new name?


If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: deleting old backups

deleting old backups www.computing.net/answers/programming/deleting-old-backups/19968.html

Batch to copy and increment folders www.computing.net/answers/programming/batch-to-copy-and-increment-folders/18395.html

Need batch file to delete old files www.computing.net/answers/programming/need-batch-file-to-delete-old-files/14092.html