How to backup and truncate all log files in a database
Some things to consider ...
- Make sure you can recover your server and database prior to issuing these commands.
- Since I am generically calling a rountine you will receive errors on the system databases.
- Your database and log files must follow the convention of name=database name_log=log file name.
- This will force the reduction of your log files and you may not be able to recover unless you have done the appropriate database backup and log backup operations (I know this is repeating item 1 ... smile )
- If you have any better ways or improvements feel free to post a comment.
Enough with the disclaimers, here is the code:
declare @sqlstring nvarchar(1024)
SET @sqlstring='use ?;DBCC SHRINKFILE (?, TRUNCATEONLY);DBCC SHRINKFILE (?_log, TRUNCATEONLY);BACKUP LOG ? WITH TRUNCATE_ONLY;DBCC SHRINKFILE (?_log, TRUNCATEONLY);';
SELECT @sqlstring;
exec master.dbo.sp_MSforeachDB @command1=@sqlstring
Comments
Anonymous
January 26, 2008
Buenas hace unos días escribí un pequeño post donde comentaba como "limpiar un poco" las basesAnonymous
January 26, 2008
Buenas hace unos días escribí un pequeño post donde comentaba como "limpiar un poco" las basesAnonymous
January 26, 2008
Buenas hace unos días escribí un pequeño post donde comentaba como "limpiar un poco" las bases de datosAnonymous
October 15, 2008
I already posted a way to truncate log, so that they do not grow indefinitly. Here a little routine found