Solved

Automate deleting of *.log files older than a month

Posted on 2007-12-03
14
900 Views
Last Modified: 2013-11-25
Is there anyway I could automate deleting of .log files older than a month.
On one of my servers. Server 2003

The logs are written to this share from a process I run .the log files eat up a lot of space when left unattended to .
0
Comment
Question by:doragbon
  • 6
  • 5
14 Comments
 
LVL 25

Expert Comment

by:jogos
ID: 20395176
If your backup is made by means of a maintenance-plan you 'll have to specify'delete after X days/weeks/months'.
Additional: when the backup fails for some reason this delete-step is not executed.
0
 
LVL 6

Expert Comment

by:PaultheBroker
ID: 20395733
Not sure what exactly you are trying to do.  You could just schedule a batch job every month to:

del c:\myLogFolder\*.log
0
 
LVL 25

Expert Comment

by:jogos
ID: 20395948
<from a process I run >
This is the key here: which proces , unless you mention which process, nobody is going to realy help you

cfr
http://msdn2.microsoft.com/en-us/library/aa214022(SQL.80).aspx
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:doragbon
ID: 20395960
I was looking at keeping *.logs for a month at a time
0
 
LVL 25

Expert Comment

by:jogos
ID: 20396089
maintenance plans : see -DelBkUps parameter
example
EXECUTE master.dbo.xp_sqlmaint N'-PlanID 66E756BE-A4A1-4F4E-ADE3-A45874E75006 -Rpt "e:\MSSQL\LOG\DB Maintenance Plan (All User Db_s)4.txt" -DelTxtRpt 6WEEKS -WriteHistory  -BkUpMedia DISK -BkUpDB "e:\MSSQL\BACKUP" -DelBkUps 8DAYS -CrBkSubDir -BkExt "BAK"'

0
 
LVL 6

Expert Comment

by:PaultheBroker
ID: 20396240
See 'Dated Directories' in this link:

http://www.speedguide.net/read_articles.php?id=1547

Run this batch job daily.  On the first day of the month it will copy your log files into directories called D:\Backup\01, on the second into D:\Backup\02 etc.   You could modify it to move rather than xcopy, and to delete the files in the destination directory before copying the new files....
0
 
LVL 6

Expert Comment

by:PaultheBroker
ID: 20396529
Assuming this is what you want to do, then copy this into a .bat file, and schedule it to run at the end of every day -
@echo off
:: variables
set newdrive=C:\LogHistory
set currentdrive=C:\DailyLog
set folder=%date:~7,2%
set copylog=xcopy /s /c /e /h /i /r /k /y
set delete=del /q /s
 
%delete% "%drive%\%folder%\*.*"
%copylog% "%currentdrive%" "%newdrive%\%folder%"
%delete% "%currentdrive%\*.*"

Open in new window

0
 
LVL 25

Expert Comment

by:jogos
ID: 20396620
We still don't know how you take your backup <The logs are written to this share from a process I run > 
This could be anything: sqlmaintenanceplan on SQL2000, a command on sQL2005, a third party tool ...

So please specify
0
 
LVL 6

Expert Comment

by:PaultheBroker
ID: 20396701
I agree - my solutions are hacks to use as a last resort if the process/application you are dealing with can't handle a more elegant solution....really this sort of control should be done at the application level.
0
 
LVL 25

Expert Comment

by:jogos
ID: 20399324
@PaultheBroker:
The roll over directories D01 - D10 or something like that is not a bad idee.
But the backup-picture must fit from the beginning to the end.  Everybody must make his choises taking into account their configuration, mix off databases-importances , transaction log or not and level of monitoring.

Maintenance plans are for some people 'not done' because unreliableautomatic cleanup. But cleanup has mainly 2 problems:
- when something went wrong it does not activate :
do you want to delete your oldest backup when the last 3 went wrong? But when no action timely taken your disk runs full.  
- attaching/detaching databases must be done taking into account the backup-model , cleaning up the backups off old databases ....

A perfect tool running unmonitored/untested can be less reliable as the dummy-way but carefully monitored .  I've seen people recovery from a lukky copie because the expensive third-party tool made unusable file-copies of live databases on tape. It's the whole picture or nothing.

 
0
 
LVL 6

Accepted Solution

by:
PaultheBroker earned 250 total points
ID: 20399521
@jogos
thanks !!!  but I not thinking of transaction logs (makes no sense to treat them this way does it????) - the question is tagged "Microsoft, Windows, Server 2003 " - so probably they aren't talking about database transaction logs at all (which are LDF not LOG files anyway)..who knows???  (just another ill-defined question on EE !!! ).  Hopefully we'll get more clarification soon.... :)
0
 
LVL 25

Assisted Solution

by:jogos
jogos earned 250 total points
ID: 20399843
A database exists of the databasefile (MDF) and its transactionlog (LDF), there could be additional database-files.
A backup can be a full backup (the whole thing) or a transaction log backup (modifications between previous backup and the moment of transaction log backup. This transactionlog backup must (and can only) be taken when a database has the recovery-model : full.

Again: it's the whole package that has to be right
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question