Skip to content

Commit

Permalink
Issue #138 - Implement WriteError
Browse files Browse the repository at this point in the history
* Add-DSClientUnixFsBackupSetItem: Implement WriteError during Operating System detection
  • Loading branch information
McGlovin1337 committed Nov 2, 2021
1 parent d0bb1cf commit cad24e2
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions PSAsigraDSClient/AddDSClientUnixFsBackupSetItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,66 @@ protected override void DSClientProcessRecord()
{
// Check DS-Client is Linux
if (DSClientSessionInfo.OperatingSystem != "Linux")
throw new Exception("Unix FileSystem Backup Sets can only be created on a Unix DS-Client");
{
ErrorRecord errorRecord = new ErrorRecord(
new PlatformNotSupportedException("Unix FileSystem Backup Sets can only be created on a Unix DS-Client"),
"PlatformNotSupportedException",
ErrorCategory.InvalidOperation,
null);
WriteError(errorRecord);
}
else
{

// Get the requested Backup Set from DS-Client
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
BackupSet backupSet = DSClientSession.backup_set(BackupSetId);
string computer = backupSet.getComputerName();
// Get the requested Backup Set from DS-Client
WriteVerbose($"Performing Action: Retrieve Backup Set with BackupSetId: {BackupSetId}");
BackupSet backupSet = DSClientSession.backup_set(BackupSetId);
string computer = backupSet.getComputerName();

// Create a Data Source Browser
DataSourceBrowser dataSourceBrowser = backupSet.dataBrowser();
// Create a Data Source Browser
DataSourceBrowser dataSourceBrowser = backupSet.dataBrowser();

// Create a List of Items
List<BackupSetItem> backupSetItems = new List<BackupSetItem>();
// Create a List of Items
List<BackupSetItem> backupSetItems = new List<BackupSetItem>();

if (ExcludeItem != null)
backupSetItems.AddRange(ProcessExclusionItems(DSClientSessionInfo.OperatingSystem, dataSourceBrowser, computer, ExcludeItem, ExcludeSubDirs));
if (ExcludeItem != null)
backupSetItems.AddRange(ProcessExclusionItems(DSClientSessionInfo.OperatingSystem, dataSourceBrowser, computer, ExcludeItem, ExcludeSubDirs));

if (RegexExcludePattern != null)
backupSetItems.AddRange(ProcessRegexExclusionItems(dataSourceBrowser, computer, RegexExclusionPath, RegexMatchDirectory, RegexCaseInsensitive, RegexExcludePattern));
if (RegexExcludePattern != null)
backupSetItems.AddRange(ProcessRegexExclusionItems(dataSourceBrowser, computer, RegexExclusionPath, RegexMatchDirectory, RegexCaseInsensitive, RegexExcludePattern));

if (IncludeItem != null)
{
foreach (string item in IncludeItem)
if (IncludeItem != null)
{
UnixFS_BackupSetInclusionItem inclusionItem = UnixFS_BackupSetInclusionItem.from(dataSourceBrowser.createInclusionItem(computer, item, MaxGenerations));
foreach (string item in IncludeItem)
{
UnixFS_BackupSetInclusionItem inclusionItem = UnixFS_BackupSetInclusionItem.from(dataSourceBrowser.createInclusionItem(computer, item, MaxGenerations));

inclusionItem.setSubdirDescend(!ExcludeSubDirs);
inclusionItem.setIncludingACL(!ExcludeACLs);
inclusionItem.setSubdirDescend(!ExcludeSubDirs);
inclusionItem.setIncludingACL(!ExcludeACLs);

if (computer.Split('\\').First() == "Local File System")
{
UnixFS_LinuxLFS_BackupSetInclusionItem linuxInclusionItem = UnixFS_LinuxLFS_BackupSetInclusionItem.from(inclusionItem);
linuxInclusionItem.setIncludingPosixACL(!ExcludePosixACLs);
}
if (computer.Split('\\').First() == "Local File System")
{
UnixFS_LinuxLFS_BackupSetInclusionItem linuxInclusionItem = UnixFS_LinuxLFS_BackupSetInclusionItem.from(inclusionItem);
linuxInclusionItem.setIncludingPosixACL(!ExcludePosixACLs);
}

backupSetItems.Add(inclusionItem);
backupSetItems.Add(inclusionItem);
}
}
}

// Get the existing specified items and store in the list
backupSetItems.AddRange(backupSet.items());
// Get the existing specified items and store in the list
backupSetItems.AddRange(backupSet.items());

// Strip any duplicates from the list, duplicates cause an error and wipes all the items from the Backup Set
backupSetItems = backupSetItems.Distinct(new BackupSetItemComparer()).ToList();
// Strip any duplicates from the list, duplicates cause an error and wipes all the items from the Backup Set
backupSetItems = backupSetItems.Distinct(new BackupSetItemComparer()).ToList();

// Add all the items to the Backup Set
WriteVerbose("Performing Action: Add Items to Backup Set");
backupSet.setItems(backupSetItems.ToArray());
// Add all the items to the Backup Set
WriteVerbose("Performing Action: Add Items to Backup Set");
backupSet.setItems(backupSetItems.ToArray());

dataSourceBrowser.Dispose();
backupSet.Dispose();
dataSourceBrowser.Dispose();
backupSet.Dispose();
}
}
}
}

0 comments on commit cad24e2

Please sign in to comment.