cancel
Showing results for 
Search instead for 
Did you mean: 

pre- post command to shrink sql transaction logs

Lykantroph
Level 4

Hi,

Ì`ve a problem, i habe a backupjob to backup the sql logs from a remote sql server, after this i shrink the transaction log files manual with a sql script directly on the sql server. What i want is the backupjob in be2012 should run the shrink job when the log backup is complete.

When i edit the backupjob, i can use the pre and post commands, i define a script with a path and fill into teh pre post commands. it doesn`t work. Maby i must use a specially syntax?

any idea?

 

Thank you

 

2 REPLIES 2

VJware
Level 6
Employee Accredited Certified

Is this how added the post command for shrink

1) Create a script file with following content called test.sql

USE database_name
ALTER DATABASE database_name SET RECOVERY SIMPLE;
DBCC SHRINKFILE(logfile_name);
ALTER DATABASE database_name SET RECOVERY FULL;

Alternatively, you can set the script using these commands - http://msdn.microsoft.com/en-us/library/ms189493%28v=sql.105%29.aspx

2) Then add the following line to the post command

sqlcmd -S sqlservername\instanceName -i C:\test.sql

Lykantroph
Level 4

Hi Vjware,

Thank you for your reply, i tryed this but it doesn`t work and i think its wrong.  When the pre post command in the be2012 job switch the database from the recovery full mode to simple mode, sql delete the logfile bevor the backup begin. When the backup is complete, the script switch back to the recovery full mode - sql create a transactionlog again.

i got the solution with the sql maintenance plan, who shrink the db logs. this task can export as script  and can use with the cmd command in the pre post command in a be job.

thank you

lykantroph