For this example I will show you how to use some of the commands to get a list of servers that have backup, find the machines that have a File System agent (Windows or Linux), check if they have a running job and start a new job if not.
The scenario for this example is you want to run an update on your servers, like a kernel patch or a Windows update. Before you do so, you want to run a backup of all your machines.
Load the module and connect to the API
Import-Module CaaS $secpasswd = ConvertTo-SecureString "mySecure123Pa$$!" -AsPlainText -Force $login= New-Object System.Management.Automation.PSCredential ("my-login-user", $secpasswd) New-CaasConnection -ApiCredentials $login -ApiBaseUri "https://api-au.dimensiondata.com/oec/0.9/"Now, you want to get a list of all the servers that have backup. Get the servers in your account and filter to those that have something in the backup field.
$serversWithBackup = Get-CaasDeployedServer | Where backup -NotLike $Null foreach ( $server in $serversWithBackup) {For each of those servers, get a list of backup clients where the agent type (e.g. File System, SQL Server, MySQL) is the File System Agent. This is either FA.LINUX or FA.WIN.
Write-Host $server.name is $server.backup.servicePlan $fileClients = Get-CaasBackupClients -Server $server | Where type -Like "FA.%"For each client, because you can have more than 1 file system client on a server, check if there is a running job by looking at the runningJob property of the client. If there is a job running, issue a warning (you can use this as an opportunity to cancel the job using " Remove-CaaSBackupJobAgent -Server $server -BackupClient $fileClient " but for my example I won't. Finally, issue a new request to start a backup using the New-CaasBackupJob command.
foreach( $fileClient in $fileClients){ if ($fileClient.runningJob.status -eq "Running") { Write-Warning "Another Job is already running for $($server.name)" } else { Write-Host Starting backup of $server.name New-CaasBackupJob -Server $server -BackupClient $fileClient } } }So in summary, the script looks like:
Import-Module CaaS $secpasswd = ConvertTo-SecureString "mySecure123Pa$$!" -AsPlainText -Force $login= New-Object System.Management.Automation.PSCredential ("my-login-user", $secpasswd) New-CaasConnection -ApiCredentials $login -ApiBaseUri "https://api-au.dimensiondata.com/oec/0.9/" $serversWithBackup = Get-CaasDeployedServer | Where backup -NotLike $Null foreach ( $server in $serversWithBackup) { Write-Host $server.name is $server.backup.servicePlan $fileClients = Get-CaasBackupClients -Server $server | Where type -Like "FA.%" foreach( $fileClient in $fileClients){ if ($fileClient.runningJob.status -eq "Running") { Write-Warning "Another Job is already running for $($server.name)" } else { Write-Host Starting backup of $server.name New-CaasBackupJob -Server $server -BackupClient $fileClient } } }
No comments:
Post a Comment