共用方式為


Backup.RetainDays 屬性

Gets or sets the number of days that must elapse before a backup set can be overwritten.

命名空間:  Microsoft.SqlServer.Management.Smo
組件:  Microsoft.SqlServer.SmoExtended (在 Microsoft.SqlServer.SmoExtended.dll 中)

語法

'宣告
Public Property RetainDays As Integer 
    Get 
    Set
'用途
Dim instance As Backup 
Dim value As Integer 

value = instance.RetainDays

instance.RetainDays = value
public int RetainDays { get; set; }
public:
property int RetainDays {
    int get ();
    void set (int value);
}
member RetainDays : int with get, set
function get RetainDays () : int 
function set RetainDays (value : int)

屬性值

型別:System.Int32
An Int32 value that specifies the retention period in days. By default, the value is set to zero.

備註

Backup set retention period is set when media is initialized. When using SQL Server Management Objects (SMO) to automate Microsoft SQL Server backup, the RetainDays property is only evaluated when the Initialize property is True.

範例

VB

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Reference the AdventureWorks2012 database.
Dim db As Database
db = srv.Databases("AdventureWorks2012")
Dim bk As New Backup
bk.Action = BackupActionType.Database
bk.Database = "AdventureWorks2012"
bk.RetainDays = 21

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$db = $srv.Databases.Item("AdventureWorks2012")
$bk = new-object Microsoft.SqlServer.Management.Smo.Backup
$bk.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
$bk.Database = "AdventureWorks2012"
$bk.RetainDays = 21

請參閱

參考

Backup 類別

Microsoft.SqlServer.Management.Smo 命名空間

其他資源

BACKUP (Transact-SQL)

備份及還原資料庫和交易記錄