Server.DeleteBackupHistory Server.DeleteBackupHistory Server.DeleteBackupHistory Method

Definition

Deletes the backup history for this instance of SQL Server up until the specified date and time.

Overloads

DeleteBackupHistory(Int32) DeleteBackupHistory(Int32) DeleteBackupHistory(Int32)

Deletes the backup history for the specified media set.

DeleteBackupHistory(String) DeleteBackupHistory(String) DeleteBackupHistory(String)

Deletes the backup history for the specified database.

DeleteBackupHistory(DateTime) DeleteBackupHistory(DateTime) DeleteBackupHistory(DateTime)

Deletes the backup history for this instance of SQL Server up until the specified date and time.

Remarks

This method has three overloads that let you delete the backup history that is stored on the instance of SQL Server. You can do this by specifying a cutoff date, a media set, the name of a database.

DeleteBackupHistory(Int32) DeleteBackupHistory(Int32) DeleteBackupHistory(Int32)

Deletes the backup history for the specified media set.

public:
 void DeleteBackupHistory(int mediaSetId);
public void DeleteBackupHistory (int mediaSetId);
Public Sub DeleteBackupHistory (mediaSetId As Integer)
Parameters
mediaSetId
Int32 Int32 Int32

An Int32 value that specifies the index number of the media set for which the backup history is deleted.

Examples

Visual Basic

'Connect to the local, default instance of SQL Server.  
Dim srv As Server  
srv = New Server  

'Delete backup history from the media set specified.  
srv.DeleteBackupHistory(1)  

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$srv.DeleteBackupHistory(1)  

Remarks

Use this method to remove backup history logs for a media set on the instance of SQL Server. If a media set is being retired, then use this method to remove the backup history only for that media set.

DeleteBackupHistory(String) DeleteBackupHistory(String) DeleteBackupHistory(String)

Deletes the backup history for the specified database.

public:
 void DeleteBackupHistory(System::String ^ database);
public void DeleteBackupHistory (string database);
Public Sub DeleteBackupHistory (database As String)
Parameters
database
String String String

A String value that specifies the name of the database for which the backup history is deleted.

Examples

'Connect to the local, default instance of SQL Server.  
Dim srv As Server  
srv = New Server  

'Delete backup history from the database specified.  
srv.DeleteBackupHistory("AdventureWorks2012")  

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$srv.DeleteBackupHistory("AdventureWorks2012")  

Remarks

Use this method to remove backup history logs for a specific database on the instance of SQL Server.

See Also

DeleteBackupHistory(DateTime) DeleteBackupHistory(DateTime) DeleteBackupHistory(DateTime)

Deletes the backup history for this instance of SQL Server up until the specified date and time.

public:
 void DeleteBackupHistory(DateTime oldestDate);
public void DeleteBackupHistory (DateTime oldestDate);
Public Sub DeleteBackupHistory (oldestDate As DateTime)
Parameters
oldestDate
DateTime DateTime DateTime

A DateTime system object value that specifies the date and time before which to delete the backup history.

Examples

Visual Basic

'Connect to the local, default instance of SQL Server.  
Dim srv1 As Server  
srv1 = New Server  

'Delete the backup history before the date specified.  
Dim odt As DateTime  
odt = New DateTime(2005, 12, 12)  
srv1.DeleteBackupHistory(odt)  

PowerShell

$srv1 = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$odt = new-object System.DateTime(2005, 12, 12)  
$srv1.DeleteBackupHistory($odt)  

Remarks

Use this method to remove old backup history logs from the instance of SQL Server. Backup history that is older than the date specified will be removed from the instance of SQL Server.

Applies to