Metoda Backup.SqlBackup
Wykonuje operacji wykonywania kopia zapasowa bazy danych określonego przez właściwości Backup obiektu użytego.
Przestrzeń nazw: Microsoft.SqlServer.Management.Smo
Zestaw: Microsoft.SqlServer.SmoExtended (w Microsoft.SqlServer.SmoExtended.dll)
Składnia
'Deklaracja
Public Sub SqlBackup ( _
srv As Server _
)
'Użycie
Dim instance As Backup
Dim srv As Server
instance.SqlBackup(srv)
public void SqlBackup(
Server srv
)
public:
void SqlBackup(
Server^ srv
)
member SqlBackup :
srv:Server -> unit
public function SqlBackup(
srv : Server
)
Parametry
- srv
Typ: Microsoft.SqlServer.Management.Smo.Server
The Server object that represents the Microsoft SQL Server instance that is the source of the backup operation.
Uwagi
Do wykonania operacji wykonywania kopia zapasowa bazy danych przy użyciu SQL Server obiektów zarządzania (SMO) aplikacja określa proces operacji przez ustawienie Backup Właściwości obiektu, a następnie wywołuje SQLBackup(Server) metoda.
Przykłady
VB
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Reference the AdventureWorks2008R2 database.
Dim db As Database
db = srv.Databases("AdventureWorks2008R2")
'Store the current recovery model in a variable.
Dim recoverymod As Integer
recoverymod = db.DatabaseOptions.RecoveryModel
'Define a Backup object variable.
Dim bk As New Backup
'Specify the type of backup, the description, the name, and the database to be backed up.
bk.Action = BackupActionType.Database
bk.BackupSetDescription = "Full backup of AdventureWorks2008R2"
bk.BackupSetName = "AdventureWorks2008R2 Backup"
bk.Database = "AdventureWorks2008R2"
'Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
Dim bdi As BackupDeviceItem
bdi = New BackupDeviceItem("Test_Full_Backup1", DeviceType.File)
'Add the device to the Backup object.
bk.Devices.Add(bdi)
'Set the Incremental property to False to specify that this is a full database backup.
bk.Incremental = False
'Set the expiration date.
Dim backupdate As New Date
backupdate = New Date(2006, 10, 5)
bk.ExpirationDate = backupdate
'Specify that the log must be truncated after the backup is complete.
bk.LogTruncation = BackupTruncateLogType.Truncate
'Run SqlBackup to perform the full database backup on the instance of SQL Server.
bk.SqlBackup(srv)
PowerShell
$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $srv.Databases.Item("AdventureWorks2008R2")
$recoverymod = $db.DatabaseOptions.RecoveryModel
$bk = new-object Microsoft.SqlServer.Management.Smo.Backup
$bk.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
$bk.BackupSetDescription = "Full backup of AdventureWorks2008R2"
$bk.BackupSetName = "AdventureWorks2008R2 Backup"
$bk.Database = "AdventureWorks2008R2"
$bdi = new-object Microsoft.SqlServer.Management.Smo.BackupDeviceItem("Test_Full_Backup1", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$bk.Devices.Add($bdi)
$bk.Incremental = $FALSE
$backupDate = new-object System.DateTime(2006, 10, 5)
$bk.ExpirationDate = $backupDate
$bk.LogTruncation = [Microsoft.SqlServer.Management.Smo.BackupTruncateLogType]::Truncate
$bk.SqlBackup($srv)