Solved

Automate deleting of *.log files older than a month

Posted on 2007-12-03
14
898 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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…
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

932 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

11 Experts available now in Live!

Get 1:1 Help Now