Showing posts with label Backup. Show all posts
Showing posts with label Backup. Show all posts

Wednesday, 8 August 2012

Cost Savings and Backup Compression


Let me set the scene, one of our internal IT SQL Servers which stores a whole host of performance metrics has over the last few months’ experienced tremendous growth as we have started to monitor more metrics on more servers.  A routine we have in place to collect and report on a multitude of server and database information including database sizes and growth highlighted this to me along with a significant decrease in free space on the backup volume.  We use SQL Server to back up our databases as opposed to a third party product as any benefits we may gain are outweighed by the cost.

When checking the backup routine on the server I noticed that we were not using backup compression.  Rather than allocating more expensive SAN storage to the volume I turned on backup compression, checking the server a day later I was pleased to report an 80% saving in cumulative backup size across the server, Happy Times! J

You can use the script below to calculate the backup compression percentage;

/*
      -----------------------------------------------------------------
      Calculate backup compression percentage per backup
      -----------------------------------------------------------------
    
      For more SQL resources, check out SQLServer365.blogspot.co.uk

      -----------------------------------------------------------------

      You may alter this code for your own purposes.
      You may republish altered code as long as you give due credit.
      You must obtain prior permission before blogging this code.

      THIS CODE AND INFORMATION ARE PROVIDED "AS IS"
     
      -----------------------------------------------------------------
*/
-- Set database context
USE msdb;
GO
-- Calculate compression ratio of all backups taken in the last 24 hours
SELECT (((backup_size - compressed_backup_size) / backup_size) * 100) AS CompressionPercentage, database_name, [type], backup_start_date
FROM msdb.dbo.backupset
WHERE backup_start_date > GETDATE()-1
ORDER BY backup_start_date DESC;
GO

Backup compression was introduced in SQL Server 2008 and although it may not have as many bells and whistles as some third party vendors it is still an extremely valuable addition to SQL Server and one which isn’t is used nearly as much as believe it should.  The saving alone in disk space makes it a no brainer surely?!  I mean 80% saving in storage across a single server is something we as DBA’s can ill afford to ignore, turning backup compression on, on an additional 4 servers this did however drop slightly to 71% but that is still a huge saving.  Let’s say that per 1TB of enterprise storage costs £5,000 even with a 50% saving using backup compression that is £2,500 saved that can be used elsewhere for training courses, conventions, books etc.  Add to this the fact that because a compressed backup is smaller than an uncompressed backup of the same data, compressing a backup typically requires less device I/O and therefore usually increases backup speed significantly.

The amount of compression you achieve will vary depending on the below factors;

·         The type of data.
Character data compresses more than other types of data.
·         The consistency of the data among rows on a page.
Typically, if a page contains several rows in which a field contains the same value, significant compression might occur for that value. In contrast, for a database that contains random data or that contains only one large row per page, a compressed backup would be almost as large as an uncompressed backup.
·         Whether the data is encrypted.
Encrypted data compresses significantly less than equivalent unencrypted data. If transparent data encryption is used to encrypt an entire database, compressing backups might not reduce their size by much, if at all.
·         Whether the database is compressed.
If the database is compressed, compressing backups might not reduce their size by much, if at all.

Before you blindly turn on backup compression there are a few things to be wary of though;

·         Compressed and uncompressed backups cannot co-exist in a media set.
·         Previous versions of SQL Server cannot read compressed backups.
·         NTbackups cannot share a tape with compressed SQL Server backups.
·         By default, compression significantly increases CPU usage.

As always, make sure any change you make has been thoroughly tested and any and all implications understood!

Enjoy!

Chris

Monday, 27 February 2012

A Script A Day - Day 22 - Database Backup

Today’s script follows on from Day 16’s script which was about database restores.  In a backwards way the script is a simple backup database script with two backup commands.  For all my production servers I have custom maintenance routines which take care of transaction log and full backups along with a whole host of other maintenance tasks.  But for a one off backup lets say before decomissioning an old server or before running some test data scripts in development then the syntax to backup a database doesn’t get much easier!  This is yet another example of T-SQL being better than using the GUI as it is far quicker ;)

Now as with my script on Day 16 not everyone knows T-SQL and thus wouldn’t be able to backup a database using it.

So I’ve included two backup database commands one will backup the SQLServer365 database to disk and one will backup the SQLServer365 database to disk with compression.  Backup compression was introduced in SQL Server 2008, details can be found on Technet.  Basically backup compression will generally save you disk space, in the example here on my instance the backup without compression was 146MB the backup with compression was 10MB!

/*
      -----------------------------------------------------------------
      Backup Database
      -----------------------------------------------------------------
     
      For more SQL resources, check out SQLServer365.blogspot.co.uk

      -----------------------------------------------------------------

      You may alter this code for your own purposes.
      You may republish altered code as long as you give due credit.
      You must obtain prior permission before blogging this code.
 
      THIS CODE AND INFORMATION ARE PROVIDED "AS IS"
     
      -----------------------------------------------------------------
*/

-- Change database context
USE master;
GO

-- Backup database
BACKUP DATABASE SQLServer365
TO DISK = 'D:\SQL\Backup\SQLServer365_20120224.bak';
GO

-- Backup database with compression
BACKUP DATABASE SQLServer365
TO DISK = 'D:\SQL\Backup\SQLServer365_20120224_Compressed.bak'
WITH COMPRESSION;
GO

Enjoy!

Chris

Friday, 20 January 2012

Database uplevel Restores Follow On

Today's post is a follow on from one earlier this month Database uplevel Restores.  I got round to testing restoring a SQL Server 2000 backup to a SQL Server 2008 R2 server and it worked!  Details Below;

-- Restore command
RESTORE DATABASE [SQL2000Test] FROM DISK = 'D:\SQL2000TestBackup.bak'
WITH REPLACE, MOVE 'SQL2000Test_Data' TO 'D:\Test\SQL2000Test_Data.mdf',
MOVE 'SQL2000Test_Log' TO 'D:\Test\SQL2000Test_Log.ldf';

Message Output;

Processed 856 pages for database 'SQL2000Test', file 'SQL2000Test_Data' on file 1.
Processed 1 pages for database 'SQL2000Test', file 'SQL2000Test_Log' on file 1.
Converting database 'SQL2000Test' from version 539 to the current version 661.
Database 'SQL2000Test' running the upgrade step from version 539 to version 551.
Database 'SQL2000Test' running the upgrade step from version 551 to version 552.
Database 'SQL2000Test' running the upgrade step from version 552 to version 611.
Database 'SQL2000Test' running the upgrade step from version 611 to version 621.
Database 'SQL2000Test' running the upgrade step from version 621 to version 622.
Database 'SQL2000Test' running the upgrade step from version 622 to version 625.
Database 'SQL2000Test' running the upgrade step from version 625 to version 626.
Database 'SQL2000Test' running the upgrade step from version 626 to version 627.
Database 'SQL2000Test' running the upgrade step from version 627 to version 628.
Database 'SQL2000Test' running the upgrade step from version 628 to version 629.
Database 'SQL2000Test' running the upgrade step from version 629 to version 630.
Database 'SQL2000Test' running the upgrade step from version 630 to version 631.
Database 'SQL2000Test' running the upgrade step from version 631 to version 632.
Database 'SQL2000Test' running the upgrade step from version 632 to version 633.
Database 'SQL2000Test' running the upgrade step from version 633 to version 634.
Database 'SQL2000Test' running the upgrade step from version 634 to version 635.
Database 'SQL2000Test' running the upgrade step from version 635 to version 636.
Database 'SQL2000Test' running the upgrade step from version 636 to version 637.
Database 'SQL2000Test' running the upgrade step from version 637 to version 638.
Database 'SQL2000Test' running the upgrade step from version 638 to version 639.
Database 'SQL2000Test' running the upgrade step from version 639 to version 640.
Database 'SQL2000Test' running the upgrade step from version 640 to version 641.
Database 'SQL2000Test' running the upgrade step from version 641 to version 642.
Database 'SQL2000Test' running the upgrade step from version 642 to version 643.
Database 'SQL2000Test' running the upgrade step from version 643 to version 644.
Database 'SQL2000Test' running the upgrade step from version 644 to version 645.
Database 'SQL2000Test' running the upgrade step from version 645 to version 646.
Database 'SQL2000Test' running the upgrade step from version 646 to version 647.
Database 'SQL2000Test' running the upgrade step from version 647 to version 648.
Database 'SQL2000Test' running the upgrade step from version 648 to version 649.
Database 'SQL2000Test' running the upgrade step from version 649 to version 650.
Database 'SQL2000Test' running the upgrade step from version 650 to version 651.
Database 'SQL2000Test' running the upgrade step from version 651 to version 652.
Database 'SQL2000Test' running the upgrade step from version 652 to version 653.
Database 'SQL2000Test' running the upgrade step from version 653 to version 654.
Database 'SQL2000Test' running the upgrade step from version 654 to version 655.
Database 'SQL2000Test' running the upgrade step from version 655 to version 660.
Database 'SQL2000Test' running the upgrade step from version 660 to version 661.
RESTORE DATABASE successfully processed 857 pages in 0.262 seconds (25.528 MB/sec).

Cheers

Chris

Friday, 6 January 2012

Database uplevel Restores

Today I've been reading Paul Randal's collection of Blogs from a series called A SQL Server DBA myth a day. If you haven't yet read it I recommend it there are a couple of misconceptions in there that I have fallen foul of in the past.  You can also find a link to the SQL Skills site in the SQL Resources section of my Blog.

Perhaps the most obvious misconception (obvious looking back and thinking about it) is listed by Paul as the below;

24x) you can restore a backup to any uplevel version of SQL Server

No. You can only restore a database from two versions back (i.e. you cannot directly restore
a SQL Server 7.0 database to SQL Server 2008).

This isn't something that I knew, I mean sure I've restored / upgraded plenty of databases in my time but never really given the number of uplevel versions a second thought. I imagine this is more a matter of luck rather than judgement on my part.

I don't have any SQL Server 7 databases to support any more but still have the odd SQL Server 2000 database. Going off this I shouldn't be able to restore a SQL Server 2000 database to a SQL Server 2008 R2 server right? I will give this a try and let you all know.

Chris