?
Solved

Automate deleting of *.log files older than a month

Posted on 2007-12-03
14
Medium Priority
?
907 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
Office 365 Training for IT Pros

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.

 

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 1000 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 1000 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

764 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