12.06.2015 Views

SQL server maintenance when using active backup - arkitex

SQL server maintenance when using active backup - arkitex

SQL server maintenance when using active backup - arkitex

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SQL</strong> <strong>server</strong> <strong>maintenance</strong> <strong>when</strong> <strong>using</strong> <strong>active</strong> <strong>backup</strong>.<br />

<strong>SQL</strong> Server maintains a set of tables in the msdb database that stores details of all<br />

<strong>backup</strong>s and restores that have been done over time. It generally remains small in size<br />

except <strong>when</strong> you are running :Arkitex Director in an <strong>active</strong> <strong>backup</strong> environment.<br />

In this case, the engine creates a <strong>backup</strong> of all of the Arkitex databases every x number<br />

of minutes (interval defined in system setup) and you can imagine that this creates a lot<br />

of entries in the msdb system database.<br />

The different tables that store these details are:<br />

• Backupset<br />

• Backupfile<br />

• Backupfilegroup (<strong>SQL</strong> Server 2005 upwards)<br />

• Backupmediaset<br />

• Backupmediafamily<br />

• Restorehistory<br />

• Restorefile<br />

• Restorefilegroup<br />

• Logmarkhistory<br />

• Suspect_pages (<strong>SQL</strong> Server 2005 upwards)<br />

Usefull <strong>SQL</strong> queries<br />

To get an idea about the kind of data saved by the <strong>SQL</strong> <strong>server</strong>:<br />

SELECT<br />

[<strong>backup</strong>_start_date]<br />

,[<strong>backup</strong>_finish_date]<br />

,[database_name]<br />

,[<strong>server</strong>_name]<br />

,[collation_name]<br />

FROM [msdb].[dbo].[<strong>backup</strong>set]<br />

ORDER BY [<strong>backup</strong>_start_date]<br />

Count the number of database <strong>backup</strong> or restores:<br />

SELECT<br />

FROM<br />

COUNT(*) AS Expr1<br />

[msdb].[dbo].[<strong>backup</strong>set]


Setting up a new <strong>SQL</strong> <strong>server</strong> <strong>maintenance</strong> task<br />

<strong>SQL</strong> <strong>server</strong> 2005<br />

Open the <strong>SQL</strong> <strong>server</strong> management studio and browse to Management\Maintenance<br />

Plan.<br />

Right click on “Maintenance Plan” and select to create a “New Maintenance Plan”.<br />

Fortunately, cleaning <strong>backup</strong>/restore history is already build-in into the <strong>SQL</strong> <strong>server</strong>.<br />

Select the task in the “Toolbox” at the left hand bottom corner and drag it onto the<br />

empty window at the right hand side.<br />

It might also be a good idea to shrink the database after it is cleaned. Drag a “Shrink<br />

Database Task” to the window on the right hand side.<br />

Connect both of the <strong>maintenance</strong> tasks: select the icon representing the history<br />

cleanup. You will now see a green arrow appearing. Select this green arrow and drag it<br />

onto the <strong>maintenance</strong> task that you want to de next (in this case the shrink database<br />

task).


Each of these tasks will have to be configured before it can be used (see the red icon<br />

inside the task). Right click on the “History Cleanup Task” and select “Edit”.<br />

In this example I decided to keep 2 weeks of <strong>backup</strong>/restore information in the msdb<br />

database.


Edit the “Shrink database task”. Here you can decide to shrink all of the databases or<br />

just a single one (msdb).


Setup the “Job Schedule Properties”.<br />

You should clean up this <strong>backup</strong>/restore history out of production hours!<br />

During this cleaning task, the sql <strong>server</strong> holds exclusive access to the msdb database<br />

and you might see sql errors in the Arkitex Client error list <strong>when</strong> the engine creates a<br />

new set of <strong>backup</strong>files. This error only indicates that <strong>SQL</strong> <strong>server</strong> was unable to add this<br />

new information inside the msdb database. There’s no danger whatsoever that you are<br />

loosing data. The <strong>backup</strong> file set should normally be created without any problem.<br />

Right click on the tab and select to “Save Selected Items” in order to save this new<br />

scheduled <strong>maintenance</strong> task.


The new task will now show up in <strong>SQL</strong> Server Agent\Jobs.<br />

Needless to say that the “<strong>SQL</strong> <strong>server</strong> agent” service needs to be running <strong>when</strong><br />

scheduling <strong>maintenance</strong> tasks.<br />

In <strong>SQL</strong> 2000<br />

Note that the previous procedure is only valid <strong>when</strong> <strong>using</strong> <strong>SQL</strong> <strong>server</strong> 2005. It will not<br />

work on the old SQl <strong>server</strong> 2000 for the simple reason that there is no such thing as a<br />

“history cleanup task”. A possible solution would be to run the following <strong>SQL</strong> <strong>server</strong><br />

commands.<br />

These commands will purge the history older then 120 days:<br />

use msdb<br />

go<br />

declare @OldestDate datetime<br />

set @OldestDate = getdate() -120<br />

exec sp_delete_<strong>backup</strong>history @OldestDate<br />

Watch out!! I have tried this and during my tests I only purged out one (1) single day of<br />

<strong>backup</strong>/restore data and it took about 10 minutes!! Purging out months or years of<br />

<strong>backup</strong>/restore history would take an incredible amount of time (hours to days) and<br />

meanwhile it would block the usage of the msdb database.<br />

Best practice would first be to find out how long it takes to purge out a single day of<br />

<strong>backup</strong>/restore history. See the examples of SQl queries that I described earlier for<br />

finding out the oldest entry in the database. You can then use the following code for<br />

purging out a history older then a specific date.<br />

Purge history older then 20/8/2011<br />

use msdb<br />

exec sp_delete_<strong>backup</strong>history '08/20/2011'<br />

The reason that is taking such a long time is that <strong>SQL</strong> 2000 is not having indexes on the<br />

tables in the msdb database. You could manually add indexes but I have never tried it.<br />

There’s enough information on the internet that can give you some assistance in this<br />

matter.<br />

See also: http://weblogs.sqlteam.com/geoffh/archive/2008/01/21/MSDB-<br />

Performance-Tuning.aspx


Initializing the Arkitex databases will NOT bring down the size of the msdb database.<br />

This msdb is a system database and not an Arkitex database. Initializing the Arkitex<br />

database is not going to wipe out the info out of the msdb database.<br />

Some facts before and after cleaning.<br />

Before cleaning After cleaning (kept 1 week) of history<br />

Number of lines in msdb 884666 5992<br />

Msdb properties (db size) 1561,63 Mb 1569,56 Mb<br />

Msdb properties (db size free 135,78 Mb 626,79 Mb<br />

space)<br />

Manually shrinked msdb after 1561.63 Mb 167,50 Mb<br />

running the <strong>maintenance</strong> task<br />

(db size)<br />

Disk Free space (windows) 27,3 Gb 26,3 Gb<br />

In my case I had a <strong>SQL</strong> <strong>server</strong> that made 884666 database <strong>backup</strong>s (used a <strong>SQL</strong> query to<br />

find out). Arkitex creates 6 <strong>backup</strong> files each time (one for each of the Arkitex<br />

databases). This means that the engine created about 147444 sets of database <strong>backup</strong> files<br />

and this happened every 10 minutes.<br />

This learned me that in total, this <strong>server</strong> did production for about 1023 days. These<br />

numbers will give you a pretty good idea of the amount of data that is kept during 2 or 3<br />

years of production (rule of thumb might be a 500 Mb per year).<br />

The automatic shrink didn’t quite work out as I expected it to be. In fact, it didn’t shrink<br />

the database at all. No idea yet what was going on but I then decided to do a manual<br />

shrink. This brought the size of the database down from 1561,63 Mb to 167,5 Mb.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!