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
Seems to work for me.
Do you have write access to that M:\TresY\testbackup folder ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, the mkdir in M:\TresY\testbackup works fine. I have only problems to download the files from the datastore. Normally that should work also, I'm admin on the datastore where I want to download the files.
Can you try with the destination directory locally on the PC where you execute the script, i.e. C:\backupFOlder ?
Perhaps the cmdlet has a problem with UNCs.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Exactly as before.
You're running the latest PowerCLI version I assume ?
Get-PowerCLIVersion
And which vCenter and ESX(i) versions are you using ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLIVersion
----------------
VMware vSphere PowerCLI 4.1 U1 build 332441
---------------
Snapin Versions
---------------
VMWare vSphere PowerCLI 4.1 U1 build 332441
vCenter 4.1.0, 258902
ESXi 4.1.0, 348481
Those are the same versions I tested against.
Does it already fail on the first file ? Or is it with the bigger .vmdk files ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It fails already at the first file.
A wild shot, can you add the following line before the Copy-DatastoreItem cmdlet ?
New-Item -Path $destination -ItemType "file" -Name test.txt
Just curious if you can write anything in that folder.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
We've tried now to connect with another user (full access) on the vCenter. With an vcenter wide admin we can download the files to M:\TresY\testbackup.
We don't want to give the helpdesk and to the backup service account full access to our vCenter.
That means you have to find out the right combination of privileges.
Once you have those you can create a new role and assign it to your helpdesk.
The vpxd logs normally contain indications of missing rights for an action.
Perhaps it is easier to start from there.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, thank you! I will check that tomorrow.
Ok, the user must have the persmission Low level file operations on the whole datacenter - only the datastore isn't enough.
Thanks for you help!