VMware

This Question is Answered

2 "helpful" answers available (6 pts)
1 Replies Last post: Mar 25, 2009 8:02 AM by LucD  

Retrieve VMX posted: Mar 24, 2009 11:10 AM

Click to view jsenon's profile Novice 5 posts since
Aug 30, 2006
Hi,

I have read some post to retrieve a vmx.


After analyse the thread I write the powershell script bellow to restrieve the esxhostname automatically with get-vmhost cmdlet :

get-vmhost | sort-object -unique | ForEach-Object -process {
& "C:\Program Files\Putty\plink.exe" -ssh -pw mypassword myaccount@$_ "find /vmfs/volumes/ -name "*.vmx" -print0 | xargs -0 tar -cf-" > c:\$_-vmxbackups.tar
}


But the tar archieve is corrupted. I think I've a bad command line.


But if I launch without powershell (for example in MS-DOS cmd windows) :

C:\Program Files\PuTTY>plink -ssh -pw xxx myaccount@myesxhostname "find /vmfs/volumes/ -name *.vmx -print0 | xargs -0 tar -cf -" > c:\myservername_vmxbackups.tar


It's work fine : the tar archive is good !


Could you Help me ?


Thanks in advance for your reply.


Regards.

Re: Retrieve VMX

1. Mar 25, 2009 8:02 AM in response to: jsenon
Click to view LucD's profile Champion 2,431 posts since
Oct 31, 2005
I use the following procedure:
1) use plink to create the tar file
2) use pscp to transfer the file

# Create tar file on ESX host

$datastore = <DS-name>
$User = <ESX-account>
$Pswd = <ESX-password>
$Computer = <ESX-hostname>
$plink = "<Putty directory>\plink.exe"
$plinkoptions = " -v -batch -pw $Pswd"
$cmd1 = 'find /vmfs/volumes/' + $datastore + '/ -name "*.vmx" -print0 | xargs -0 tar -uvf ~/transfer.tar'

$remoteCommand = '"' + $cmd1 + '"'
$command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

$msg = Invoke-Expression -command $command 

# Transfer tar file to local station

$pscp = "<Putty directory>\pscp.exe"
$pscpoptions = "-pw $Pswd"
$lcmd = $pscp + " " + $pscpoptions + " " + $User + "@" + $computer + ":/home/" + $User + "/transfer.tar" + " " + "C:\transfer.tar"

$msg = Invoke-Expression -command $lcmd

See Script to pull log files from ESX hosts for details on how to set up the sudo part on the ESX server side.

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities