Automating Archive of K2Log Database

  • 5 November 2008
  • 5 replies
  • 4 views

Badge +3

Hi,


Our K2Log database is very large and can cause performance issues on the server when we try and back up the disk. As a result of this, I have been tasked with finding a way to reduce the size of the database and keep it under control in future.


I have found that K2.net 2003 SP3 (which is what we are running) offers an archiving tool, which I have tested and confirmed that it provides the result I want.


While browsing the net for this, I came across a blog which contained this script for automating the process:


 Set the old archive start date
Set @maxPreviousArchiveStartDate=(Select max(FromDate) From _ArchiveTo)

– Set the archive start date
Set @archiveStartDate = @maxPreviousArchiveStartDate
Set @archiveStartDate = DateAdd(month, 1, @archiveStartDate) — add one month
Set @archiveStartDate = Cast(DatePart(dd, @archiveStartDate) as varchar) + ‘/’
      + Cast(DatePart(mm, @archiveStartDate) as varchar) + ‘/’
      + Cast(DatePart(yyyy, @archiveStartDate) as varchar)

– Set the archive end date
Set @archiveEndDate = @maxPreviousArchiveStartDate
Set @archiveEndDate = DateAdd(month, 2, @archiveEndDate)
Set @archiveEndDate = DateAdd(day,-1, @archiveEndDate)
Set @archiveEndDate = Cast(DatePart(dd, @archiveEndDate) as varchar) + ‘/’
     + Cast(DatePart(mm, @archiveEndDate) as varchar) + ‘/’
     + Cast(DatePart(yyyy, @archiveEndDate) as varchar)

Set @command = ‘”‘ + (Select ApplicationValue From AppDB..ApplicationControl
  Where ApplicationGroup=’K2 Archive’ And ApplicationKey=’K2 Archive Creation’) + ‘”‘ + ‘ [’ + @archiveStartDate + ‘] [’ + @archiveEndDate + ‘]’

Exec master..xp_cmdshell @command

EXEC msdb.dbo.sp_send_dbmail
  @profile_name = ‘K2 Archiving’,
  @recipients = ‘k2admin@abc.com’,        
  @subject = ‘K2 Archiving Notification’,
  @body = ‘K2 Archiving job is completed.’



If you ignore the slightly dodgy parts of syntax and invalid characters I was wondering if anyone could help me get this to work. The bit I'm particularly struggling to understand is the line that starts 'Set @command' What is this doing? What is it for?


Another thought that crossed my mind was that there may be some system specific names in there which I wasn't aware of, if anyone spots any of these then please point them out and let me know, in generic terms, what they should be.


Any help with automating the process not related to this script is also very welcome.


TIA


M


5 replies

Badge +7
From the part of code that you provided, It is hard to tell what the codes are going to do. Because you mention that you found this code from a blog entry, May I have the blog URL to read the full story in order to help you?
Badge +13

What is the size of your K2 and K2Log databases?

I was able to use SQLTrace to find out the necc. SQL stmts and customize the SQLs to only archive process specific items.

I haven't made it into an automated script.    The original blog you got it from probably has this info - if you could post the URL.

 

Badge +3

Unfortunately where i have been distracted by bigger issues I ohave only just ahd a chance to come back to this problem. Annoyingly the blog I got this from has disappeared, so I can't post a link. :-(


Does anyone know how I might be able to automate this process? If there are command line arguments or something then I could just use Windows Scheduled Tasks no? Does anyone know what arguments there might be for this tool?


TIA

Badge +1

There is a document which describes this in the knowledge base located at

 http://downloads.k2.com/Data/SP3/K2.net%202003%20Archive%20Components%20(3.6090.1.0).pdf

Aside from that, what you have shown would not run the archive. To run the arvhive from within SQL Server all you have to use is the following script: 

 

********************************************************************************************** 
DECLARE @startDate varchar(12)

DECLARE @endDate varchar(12)

DECLARE @command varchar(255)

SET @startDate = '01/01/2005'

SET @endDate = '31/01/2005'

SET @command = 'c:K2ArchiveK2Archive.exe ' + @startDate + ' ' + @endDate

exec master..xp_cmdshell @command

**********************************************************************************************

You could add this script to a scheduled job within your SQL Server Agent. This assumes that you have configured the K2Archive.exe.config file.

The script you have did have some logic you can borrow to set the dates. It would have never run the archive tool, you must have missed a piece of the code on that old site. I hope the snippet above gives you the help you need to get under way.

 

Thanks,

Ryan Watts 

Badge +9
where can I get this Archive utility tool???

Reply