SMO Sample: Backup database to Mirrors
Purpose of sample: Backup database to various mirrors
Server svr = new Server();
Backup b = new Backup();
b.BackupSetDescription = "Set description";
b.Action = BackupActionType.Database;
b.BackupSetName = "Backup set #1";
b.Database = "msdb";
b.MediaDescription = "Media description";
b.MediaName = "Media name";
b.Devices.AddDevice(@"c:\back1a.bak", DeviceType.File);
b.Devices.AddDevice(@"c:\back1b.bak", DeviceType.File);
BackupDeviceList[] la = new BackupDeviceList[2];
BackupDeviceList l1 = new BackupDeviceList();
l1.AddDevice(@"c:\back2a.bak", DeviceType.File);
l1.AddDevice(@"c:\back2b.bak", DeviceType.File);
BackupDeviceList l2 = new BackupDeviceList();
l2.AddDevice(@"c:\back3a.bak", DeviceType.File);
l2.AddDevice(@"c:\back3b.bak", DeviceType.File);
la[0] = l1;
la[1] = l2;
b.Mirrors = la;
b.FormatMedia =
true;
b.Initialize = true;
b.SkipTapeHeader = true;
b.SqlBackup(svr);
Disclaimer: this sample doesn't handle exceptions and may not function as expected. Use at own risk. It is good practice to test an application before using it in production.
Comments
- Anonymous
January 19, 2008
<a href= http://index1.trum4u.com >aol greating cards</a>