Solved

Automate deleting of *.log files older than a month

Posted on 2007-12-03
14
905 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

687 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