Solved

Automate deleting of *.log files older than a month

Posted on 2007-12-03
14
897 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now