Warning: this code is provided on a best effort basis and is not in any way officially supported or sanctioned by Cohesity. The code is intentionally kept simple to retain value as example code. The code in this repository is provided as-is and the author accepts no liability for damages resulting from its use.
This powershell script archives local snapshots older than x days. This is useful if you have created an archive target (e.g. AWS S3) and want to programatically archive existing local snapshots.
Run these commands from PowerShell to download the script(s) into your current directory
# Download Commands
$scriptName = 'archiveOldSnapshots'
$repoURL = 'https://raw.githubusercontent.com/bseltz-cohesity/scripts/master/powershell'
(Invoke-WebRequest -Uri "$repoUrl/$scriptName/$scriptName.ps1").content | Out-File "$scriptName.ps1"; (Get-Content "$scriptName.ps1") | Set-Content "$scriptName.ps1"
(Invoke-WebRequest -Uri "$repoUrl/cohesity-api/cohesity-api.ps1").content | Out-File cohesity-api.ps1; (Get-Content cohesity-api.ps1) | Set-Content cohesity-api.ps1
# End Download Commands
- archiveOldSnapshots.ps1: the main powershell script
- cohesity-api.ps1: the Cohesity REST API helper module
Place both files in a folder together, then we can run the script.
First, run the script WITHOUT the -archive switch to see what would be archived.
./archiveOldSnapshots.ps1 -vip mycluster `
-username myuser `
-domain mydomain.net `
-vault s3 `
-jobNames 'SQL Backup', 'NAS Backup' `
-keepFor 365
searching for old SQL Backup snapshots...
SQL Backup: would archive 12/11/2019 01:00:01 until 2019-12-16
SQL Backup: would archive 12/12/2019 01:00:01 until 2019-12-17
SQL Backup: would archive 12/13/2019 01:00:01 until 2019-12-18
searching for old NAS Backup snapshots...
NAS Backup: would archive 12/11/2019 01:20:00 until 2019-12-16
NAS Backup: would archive 12/12/2019 01:20:01 until 2019-12-17
NAS Backup: would archive 12/13/2019 01:20:01 until 2019-12-18
Then, if you're happy with the list of snapshots that will be archived, run the script again and include the -archive switch. This will execute the archive tasks
./archiveOldSnapshots.ps1 -vip mycluster `
-username myuser `
-domain mydomain.net `
-vault s3 `
-jobNames 'SQL Backup', 'NAS Backup' `
-keepFor 365 `
-archive `
-includeLogs
- -vip: Cohesity Cluster to connect to
- -username: Cohesity username
- -domain: (optional) Cohesity logon domain (defaults to local)
- -vault: Name of archive target
- -jobNames: (optional) One or more job names to archive (comma separated)
- -jobList: (optional) text file of job names (one per line)
- -keepFor: (optional) keep archive for X days (from original backup date)
- -ifExpiringAfter: (optional) skip if local snapshot set to expire in X or less days
- -olderThan: (optional) skip if local snapshot is newer than X days
- -archive: (optional) if excluded script will only report what it would do (test run mode)
- -includeLogs: (optional) also archive log backups (default is to only archive full and incremental backups)
- -dates: (optional) one or more dates to archive, comma separated (e.g. 2021-04-23, 2021-04-24)
To monitor the archive tasks, see the script 'monitorArchiveTasks'
For additional help running and scheduling Cohesity PowerShell scripts, please see https://github.com/bseltz-cohesity/scripts/blob/master/powershell/Running%20Cohesity%20PowerShell%20Scripts.pdf