Compartilhar via


SPBackupRestoreConsole.DiskSize method

Obtém o espaço total em disco em um volume e a quantidade do que espaço disponível para o usuário (como parâmetros de out ).

Namespace:  Microsoft.SharePoint.Administration.Backup
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaração
Public Shared Function DiskSize ( _
    dir As String, _
    <OutAttribute> ByRef freeBytesAvailable As ULong, _
    <OutAttribute> ByRef totalBytes As ULong _
) As Integer
'Uso
Dim dir As String
Dim freeBytesAvailable As ULong
Dim totalBytes As ULong
Dim returnValue As Integer

returnValue = SPBackupRestoreConsole.DiskSize(dir, _
    freeBytesAvailable, totalBytes)
public static int DiskSize(
    string dir,
    out ulong freeBytesAvailable,
    out ulong totalBytes
)

Parâmetros

  • dir
    Type: System.String

    Um caminho, possivelmente um caminho UNC no volume cujas informações de espaço é necessário.

  • freeBytesAvailable
    Type: System.UInt64

    Quando esse método retorna, contém um DiskSize que representa o total de bytes disponível no volume onde está localizado, para o usuário em cujo contexto DiskSize é chamado dir . Este parâmetro é passado não inicializado.

  • totalBytes
    Type: System.UInt64

    Quando esse método retorna, contém um DiskSize que representa o total de bytes no volume onde se encontra dir . Este parâmetro é passado não inicializado.

Valor retornado

Type: System.Int32
0, se falhar a tentativa de tamanho de disco do relatório; Caso contrário, alguns outros Int32, que significa que a operação foi bem-sucedida.

Comentários

Normalmente, o dir é o caminho onde você deseja armazenar o backup, mas qualquer caminho válido no mesmo volume pode ser usado e os parâmetros de out retornará os mesmos valores.

Examples

O exemplo a seguir mostra o método DiskSize usado para determinar se o volume de backup possui espaço suficiente para conter os componentes de backup. Para o exemplo completo e uma discussão detalhada sobre ele, consulte 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

Ver também

Referência

SPBackupRestoreConsole class

SPBackupRestoreConsole members

Microsoft.SharePoint.Administration.Backup namespace