![]() |
home
articles
news
code
blog
links
search
| ||
![]() ![]() ![]() |
Overview In this series of articles, I'll demonstrate how to use SMO (SQL Management Objects) to do a variety of common DBA tasks including Backups, Restores,Index Maintenance, Integrity checks and more. These are some of the operations available in the SMO database maintenance utility available on this site - ExpressMaint. In this article we will concentrate on how to perform backups using SMO in SQL2005. For information on how to build and compile a SMO application please review Getting Started with SMO in SQL 2005. Database Backups In order to perform a backup using SMO we require two objects, a Server object and a Backup object. In its simplest form, a Backup object requires only a few properties to be set before calling the SqlBackup method and passing in the Server object as can be seen in the following example that does a Full database backup of the SMO database to the file c:\SMOTest.bak
There are many other properties that can be set for the Backup object. For the full list see the Backup Object in Books On Line (if you have SQL2005 Books On Line installed click this link to be taken to the correct page). Filegroup Backups In the example below, just the WorkOrderGroup filegroup of the Adventureworks database is backed up (the script to convert the AdventureWorks OLTP demo database into a multi filegroup database can be found in the SQL Server Engine samples and by default is located in C:\Program Files\Microsoft SQL Server\90\Samples\Engine\Administration\FileGroups\Scripts). Filegroups to be backed up are specified by adding them to the Backup objects DatabaseFileGroups collection. In order to backup specific files, they can be added to the DatabaseFiles collection.
Differential Backups Performing a differential backup is very straightforward, simply set the Incremental property of the Backup object to True
Log Backups Log backups are equally straightforward, simply set the Action property of the Backup object to BackupActionType.Log
Related Articles Getting Started with SMO in SQL 2005 Getting Started with SMO in SQL 2005 - Restores Getting Started with SMO in SQL 2005 - Integrity Checks Getting Started with SMO in SQL 2005 - Verifying Backups
|
|||||||||||||||||||||||
| © Copyright sqldbatips Ltd 2008. Contact webmaster | home | news | articles | code | blog | links | search | |