SPBackupRestoreConsole.DiskSizeRequired 方法 (Guid, SPBackupRestoreObject)
在树中指定的备份操作中的组件获取备份指定的节点 (和其子项) 所需的磁盘空间量。
命名空间: Microsoft.SharePoint.Administration.Backup
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Shared Function DiskSizeRequired ( _
id As Guid, _
node As SPBackupRestoreObject _
) As ULong
用法
Dim id As Guid
Dim node As SPBackupRestoreObject
Dim returnValue As ULong
returnValue = SPBackupRestoreConsole.DiskSizeRequired(id, _
node)
public static ulong DiskSizeRequired(
Guid id,
SPBackupRestoreObject node
)
参数
id
类型:System.GuidGuidSPBackupRestoreConsoleObject表示备份操作的 ID。
node
类型:Microsoft.SharePoint.Administration.Backup.SPBackupRestoreObject表示如果由id操作的过程会备份该组件的SPBackupRestoreObject 。
返回值
类型:System.UInt64
UInt64 表示的空间,以字节为单位,所需的备份操作。
备注
DiskSizeRequired方法将合计DiskSizeRequired值的备份操作中包含的所有对象。它还添加了 1k 字节为单位) 以确保它始终返回 1 K 的最小值。
如果返回MaxValue() , id不包含有效的备份对象。
示例
下面的示例演示用来确定备份卷是否有足够的空间来存放要备份的组件的DiskSizeRequired方法。有关完整的示例和详细的讨论,请参阅How to: Programmatically Back Up Content。
private static Boolean EnsureEnoughDiskSpace(String location, Guid backup, SPBackupRestoreObject node)
{
UInt64 backupSize = SPBackupRestoreConsole.DiskSizeRequired(backup, node);
UInt64 diskFreeSize = 0;
UInt64 diskSize = 0;
Boolean hasEnoughSpace = true;
try
{
SPBackupRestoreConsole.DiskSize(location, out diskFreeSize, out diskSize);
}
catch
{
diskFreeSize = diskSize = UInt64.MaxValue;
}
if (backupSize > diskFreeSize)
{
// Report through your UI that there is not enough disk space.
Console.WriteLine("{0} bytes of space is needed but the disk hosting {1} has only {2}.", backupSize, location, diskFreeSize);
Console.WriteLine("Please try again with a different backup location or a smaller component.");
hasEnoughSpace = false;
}
else if (backupSize == UInt64.MaxValue || diskFreeSize == 0)
{
// Report through your UI that it cannot be determined whether there is enough disk space.
Console.WriteLine("Cannot determine if that location has enough disk space.");
Console.WriteLine("Please try again with a different backup location or a smaller component.");
hasEnoughSpace = false;
}
return hasEnoughSpace;
}// end EnsureEnoughDiskSpace
Private Shared Function EnsureEnoughDiskSpace(ByVal location As String, ByVal backup As Guid, ByVal node As SPBackupRestoreObject) As Boolean
Dim backupSize As UInt64 = SPBackupRestoreConsole.DiskSizeRequired(backup, node)
Dim diskFreeSize As UInt64 = 0
Dim diskSize As UInt64 = 0
Dim hasEnoughSpace As Boolean = True
Try
SPBackupRestoreConsole.DiskSize(location, diskFreeSize, diskSize)
Catch
diskSize = UInt64.MaxValue
diskFreeSize = diskSize
End Try
If backupSize > diskFreeSize Then
' Report through your UI that there is not enough disk space.
Console.WriteLine("{0} bytes of space is needed but the disk hosting {1} has only {2}.", backupSize, location, diskFreeSize)
Console.WriteLine("Please try again with a different backup location or a smaller component.")
hasEnoughSpace = False
ElseIf backupSize = UInt64.MaxValue OrElse diskFreeSize = 0 Then
' Report through your UI that it cannot be determined whether there is enough disk space.
Console.WriteLine("Cannot determine if that location has enough disk space.")
Console.WriteLine("Please try again with a different backup location or a smaller component.")
hasEnoughSpace = False
End If
Return hasEnoughSpace
End Function ' end EnsureEnoughDiskSpace