SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


delete log file


delete log file

Author
Message
sqlfriends
sqlfriends
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3830 Visits: 4011
I would like to use http://ola.hallengren.com/ script.

There are log output files created in the folder of MSSQL\log.

How can I setup a job to delete the old ones, I don't see that is include in maintenance job.

Or I missed it?

Thanks
Ola Hallengren
Ola Hallengren
Old Hand
Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)Old Hand (330 reputation)

Group: General Forum Members
Points: 330 Visits: 1938
There is a job, [Output File Cleanup], that is taking care of that. It is created by http://ola.hallengren.com/scripts/MaintenanceSolution.sql.

Ola Hallengren
http://ola.hallengren.com
sqlfriends
sqlfriends
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3830 Visits: 4011
Thanks a lot. I will check into it.
asantangelo
asantangelo
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 291
One thing we recently learned about the command created in Ola's output file cleanup job is that if you are using a UNC path for your backups and/or Agent Job log files then the CmdExe script will not work as UNC paths are not supported.

In our case and as a temporary solution, since we have a 3 node cluster using SQL 2014 Availability Groups where only the backup volumes are leveraging the same shared storage volumes for our backups, we opted for just altering the Output File Cleanup jobs to use the physical drive letters since these shared volumes are usually hosted on the same node. Of course I the event of a failover we would have to make a manual adjustment but that is a better option than not cleaning up the Agent job files at all.
Johan Arvidsson
Johan Arvidsson
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 6
I looked at the "Output File Cleanup" Job in Ola Hallengrens script and rewrote it in powershell.

Turning this:

cmd /q /c "For /F "tokens=1 delims=" %v In ('ForFiles /P "$(ESCAPE_SQUOTE(SQLLOGDIR))" /m *_*_*_*.txt /d -30 2^>^&1') do if EXIST "$(ESCAPE_SQUOTE(SQLLOGDIR))"\%v echo del "$(ESCAPE_SQUOTE(SQLLOGDIR))"\%v& del "$(ESCAPE_SQUOTE(SQLLOGDIR))"\%v"



Into this:

powershell.exe -command & {get-childitem -path "$(ESCAPE_SQUOTE(SQLLOGDIR))"  -filter *_*_*_*.txt | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | remove-item -verbose}



It should handle UNC paths and i think it is a little bit easier on the eye. Cmd is probably faster to execute and it will probably work the same pretty much anywhere, the powershell snippet above has not been tested in production so be aware of that. I just did it for the sake of learning and i did it on SQL Server 2014 SP1 Enterprise. But if anyone else finds it useful, nobody is happier than me. Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search