Skip to content

Commit

Permalink
File snapshot information (#228)
Browse files Browse the repository at this point in the history
* Fixed issue in constructing job url for fetching job list
Issue: #226
Cause: Job name contains special character need to be encoded
Fix: Encoding query name list before constructing job url

* Included powershell commandlet for colletcing file snapshot informations.

* Modified restore file script to fetch latest recoverable snapshot detail, if job run detail not provided by the user.

* Removed cluster id and cluster incarnation id parameter in find cohesity snapshot cmdlet.

* Hard-coded value for target host type is not correct in remotefile restore cmdlet, which need to be assigned based on source host type.

* Updated restore file example in readme file.

---------

Co-authored-by: unknown <kshanmugam.maplelabs@corp.cohesity.com>
  • Loading branch information
KavishreeShanmugam11 and unknown authored Aug 18, 2023
1 parent 4a5f17e commit eed2a12
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 49 deletions.
85 changes: 85 additions & 0 deletions docs/cmdlets-reference/find-cohesityfilesnapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Find-CohesityFileSnapshot

## SYNOPSIS
Get the information about snapshots that contain the specified file or folder. In addition, information about the file or folder is provided.

## SYNTAX

```
Find-CohesityFileSnapshot [-ClusterId <Int64>] [-ClusterIncarnationId <Int64>] [-FileName <String>] [-JobId <Int64>]
[-SourceId <Int64>] [<CommonParameters>]
```

## EXAMPLES

### EXAMPLE 1
```
Find-CohesityFileSnapshot -FileName "abc.txt" -SourceId 123 -JobId 11
```

Returns snapshot information of specified file/folder in metioned source.

## PARAMETERS

### -FileName
Specifies the name of the file or folder to find in the snapshots.
This field is required.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -JobId
Specifies the id of the Job that captured the snapshots.
These snapshots are searched for the specified files or folders.
This field is required.
```yaml
Type: Int64
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -SourceId
Specifies the id of the Protection Source object (such as a VM) to search.
When a Job Run executes, snapshots of the specified Protection Source
object are captured. This operation searches the snapshots of the
object for the file or folder. This field is required.
```yaml
Type: Int64
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
### Cohesity.Model.FileSnapshotInformation
## NOTES
## RELATED LINKS
15 changes: 11 additions & 4 deletions docs/cmdlets-reference/restore-cohesityfile.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Restore-CohesityFile

## SYNOPSIS
Restores the specified files or folders from a previous backup.
Restores the specified files or folders.

## SYNTAX

Expand All @@ -14,7 +14,7 @@ Restore-CohesityFile -TaskName <String> -FileNames <String[]> -JobId <Int64> -So
```

## DESCRIPTION
Restores the specified files or folders from a previous backup.
Request to create a Restore Task for recovering files or folders.

## EXAMPLES

Expand All @@ -23,14 +23,21 @@ Restores the specified files or folders from a previous backup.
Restore-CohesityFile -TaskName "restore-file-vm" -FileNames /C/data/file.txt -JobId 1234 -SourceId 843 -TargetSourceId 856 -TargetParentSourceId 828 -TargetHostType KWindows -TargetHostCredential (Get-Credential)
```

Restores the specified file to the target windows VM with the source id 856 from the latest backup.
Restores the file from the specified source to the target windows VM from the latest backup.

### EXAMPLE 2
```
Restore-CohesityFile -TaskName "restore-file-vm" -FileNames /C/data/file.txt -JobId 1234 -JobRunId 3005 -StartTime 1690646467987573 -SourceId 843 -TargetSourceId 856 -TargetParentSourceId 828 -TargetHostType KWindows -TargetHostCredential (Get-Credential)
```

Restores the file from the specified source to the target windows VM from the specified snapshot.

### EXAMPLE 3
```
Restore-CohesityFile -TaskName "restore-file-physical" -FileNames /C/data/file.txt -JobId 1234 -SourceId 820 -TargetSourceId 858
```

Restores the specified file to the target physical server with the source id 858 from the latest backup.
Restores the file from the specified source to the target physical server using the latest backup.

## PARAMETERS

Expand Down
20 changes: 11 additions & 9 deletions docs/cmdlets-reference/restore-cohesityremotefile.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Restore-CohesityRemoteFile

## SYNOPSIS
Restores the specified files or folders from a previous backup from a remote cluster.
Restores the specified files or folders from a remote cluster.

## SYNTAX

Expand All @@ -13,7 +13,7 @@ Restore-CohesityRemoteFile [[-TaskName] <String>] [-FileNames] <String[]> [-JobI
```

## DESCRIPTION
Restores the specified files or folders from a previous backup from a remote cluster.
Request to create a Restore Task for recovering files or folders from a remote target.

## EXAMPLES

Expand All @@ -22,19 +22,21 @@ Restores the specified files or folders from a previous backup from a remote clu
Restore-CohesityRemoteFile -TaskName "restore-file-vm" -FileNames /C/data/file.txt -JobId 1234 -SourceId 843 -TargetSourceId 856 -TargetParentSourceId 828 -TargetHostCredential (Get-Credential)
```

Restores the specified file to the target windows VM with the source id 843 from the latest backup.
Get the job id from $jobs = Get-CohesityProtectionJob -Environments KVMware
Get the source id from $jobs\[0\].sourceIds
Get the target details $targets = Get-CohesityProtectionSourceObject -Environments KVMware
Get the target source id $targets\[2\].id
Get the target parent source id $targets\[2\].parentId
Restores the file from the specified source to the target windows VM using the latest backup from remote target.

### EXAMPLE 2
```
Restore-CohesityRemoteFile -TaskName "restore-file-vm" -FileNames /C/data/file.txt -JobId 1234 -JobRunId 3005 -StartTime 1690646467987573 -SourceId 843 -TargetSourceId 856 -TargetParentSourceId 828 -TargetHostType KWindows -TargetHostCredential (Get-Credential)
```

Restores the file from the specified source to the target windows VM using the specified snapshot from remote target.

### EXAMPLE 3
```
Restore-CohesityRemoteFile -FileNames "/C/myFolder" -NewBaseDirectory "C:\temp\restore" -JobId 61592 -SourceId 3517 -TargetSourceId 3098
```

Restores the specified file to the target physical server with the source id 3517 from the latest backup.
Restores the file from the specified source to the target physical server using the latest backup from remote target.

## PARAMETERS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ protected override void ProcessRecord()
queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));

var url = $"/public/restore/files{queryString}";
WriteObject(url);
var result = Session.ApiClient.Get<FileSearchResults>(url);
WriteObject(result.Files, true);
if (Paginate != null && Paginate.HasValue)
Expand Down
16 changes: 14 additions & 2 deletions src/Cohesity.Powershell/Cmdlets/Recovery/RestoreCohesityFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,26 @@ protected override void ProcessRecord()
}
};

// Collect the recoverable snapshot information of specified file/folder
var queryString = new QuerystringBuilder();
foreach(var filename in FileNames)
{
queryString.Add("filename", filename);
}
queryString.Add("sourceId", SourceId);
queryString.Add("jobId", JobId);

var snapshotUrl = $"/public/restore/files/snapshotsInformation{ queryString.Build()}";
var snapshotInfo = Session.ApiClient.Get<Model.FileSnapshotInformation[]>(snapshotUrl);

// If job run id is not specified, get the job run id of the last run
if (JobRunId.HasValue)
{
restoreObject.JobRunId = JobRunId;
}
else
{
restoreObject.JobRunId = job.LastRun.BackupRun.JobRunId;
restoreObject.JobRunId = snapshotInfo[0].Snapshot.JobRunId;
}

// If start time is not specified, get the start time of the last run
Expand All @@ -266,7 +278,7 @@ protected override void ProcessRecord()
}
else
{
restoreObject.StartedTimeUsecs = job.LastRun.BackupRun.Stats.StartTimeUsecs;
restoreObject.StartedTimeUsecs = snapshotInfo[0].Snapshot.StartedTimeUsecs;
}

restoreRequest.SourceObjectInfo = restoreObject;
Expand Down
3 changes: 2 additions & 1 deletion src/Cohesity.Powershell/Cohesity.PowerShell.Core.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RootModule = 'Cohesity.PowerShell.Core.dll'

# Version number of this module.
ModuleVersion = '1.9.2'
ModuleVersion = '1.9.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -75,6 +75,7 @@ FunctionsToExport = @(
'Copy-CohesityMSSQLObject',
'Copy-CohesityView',
'Copy-CohesityVMwareVM',
'Find-CohesityFileSnapshot',
'Get-CohesityActiveDirectory',
'Get-CohesityCmdletConfig',
'Get-CohesityExternalClient',
Expand Down
3 changes: 2 additions & 1 deletion src/Cohesity.Powershell/Cohesity.PowerShell.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RootModule = 'Cohesity.PowerShell.dll'

# Version number of this module.
ModuleVersion = '1.9.2'
ModuleVersion = '1.9.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -75,6 +75,7 @@ FunctionsToExport = @(
'Copy-CohesityMSSQLObject',
'Copy-CohesityView',
'Copy-CohesityVMwareVM',
'Find-CohesityFileSnapshot',
'Get-CohesityActiveDirectory',
'Get-CohesityCmdletConfig',
'Get-CohesityExternalClient',
Expand Down
Loading

0 comments on commit eed2a12

Please sign in to comment.