Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all articles
Browse latest Browse all 9071

Backup VMs with Copy-DatastoreItem

$
0
0

Hi

 

I'm trying to write a script who backups the VMs of our helpdesk. They have some testmachines, who need only a basic backup.

 

The Script:

function backupvm($name, $destination) {    $test = Test-Path $destination       if($test -eq $false) {        mkdir $destination    }       Copy-DatastoreItem MyDS:\$name\* $destination
}
# Set variables
$server = "vCenterServer"
$folder = "Testclients CLC"
$ds = "datastore"
$backupdestination = "M:\TresY\testbackup"

# Connect to $Server
connect-viserver $server

# Generates a PSDrive
$datastore = Get-Datastore $ds
New-PSDrive -Name MyDS -PSProvider ViMdatastore -Root '\' -location $datastore

# Suspends all started VMs
Write-Host "VMs are now backupped:"
Get-VM -location $folder | Foreach-Object {
    if($_.PowerState -eq "PoweredOn") {        Suspend-VM -VM $_.Name -Confirm:$false               backupvm $_.Name $backupdestination"\"$_               Start-VM -VM $_.Name -Confirm:$false        Write-Host $_.FullName    } Else {        backupvm $_.Name $backupdestination"\"$_        Write-Host $_.Name    }
}


When I execute it, followed error arrives:

Copy-DatastoreItem : 12.04.2011 08:42:24    VimDatastore        Download of fil
e 'https://vCenterServer:443/folder%2ft008002%2fvmware.log?dcPath=
Biel&dsName=DateStore' failed. Error message: The remote serv
er returned an error: (401) Unauthorized.
At C:\Temp\powershell\backups-testesxi21.ps1:19 char:23
+     Copy-DatastoreItem <<<<  -Item MyDS:\$name\* -Destination $destination
    + CategoryInfo          : NotSpecified: (:) [Copy-DatastoreItem], VimExcep
   tion
    + FullyQualifiedErrorId : Client20_StorageServiceImpl_DownloadFile_Downloa
   dFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.CopyDatastoreItem

 

From MyDS to MyDS i can copy the files without problmes. But to my local path on M:\TresY\testbackup i receive the error.

 

Any ideas?

 

Thanks!
Yannick


Viewing all articles
Browse latest Browse all 9071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>