Recover vmx from log file: Difference between revisions
New page: === Recover vmx from log file === On the VMware community forums, [http://communities.vmware.com/people/etung|Eric Tung] has devised a little jewel of code that automates recreating a vmx ... |
Update to parse and retrieve vmx file from current vmware.log files. |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=== Recover vmx from log file === | === Recover vmx from log file === | ||
On the VMware community forums, [http://communities.vmware.com/people/etung | On the VMware community forums, [http://communities.vmware.com/people/etung Eric Tung] has devised a little jewel of code that automates recreating a vmx file from a recent vmware.log file. | ||
This is possible as on every boot of a virtual machine, the vmware.log gets a copy from your virtual hardware settings written out into the vmware.log logfile along with some extra information such as the date and time this VM was run. | This is possible as on every boot of a virtual machine, the vmware.log gets a copy from your virtual hardware settings written out into the vmware.log logfile along with some extra information such as the date and time this VM was run. | ||
Line 7: | Line 7: | ||
==== vmxRecover.pl code ==== | ==== vmxRecover.pl code ==== | ||
As of Fusion 4, the format of the vmware.log has changed. Here's the script for parsing log files from before Fusion 4 | |||
#!/usr/bin/perl | #!/usr/bin/perl | ||
use strict; | use strict; | ||
use warnings; | use warnings; | ||
if ($#ARGV != 0) { | if ($#ARGV != 0) { | ||
print "Recovers .vmx files from .log files. Usage:\n"; | print "Recovers .vmx files from .log files. Usage:\n"; | ||
Line 25: | Line 28: | ||
if (/: vmx\| DICT --- \S/) { last; } # Keep going until the next section | if (/: vmx\| DICT --- \S/) { last; } # Keep going until the next section | ||
s/^.*: vmx\| DICT\s*//; # Strip off the leading timestamp and other stuff | s/^.*: vmx\| DICT\s*//; # Strip off the leading timestamp and other stuff | ||
s/\r//; # Get rid of any \r's that may have somehow snuck in | |||
s/([^=]*=) (.*)/$1 "$2"/; # Quote the value | |||
print; | |||
} | |||
New version to use for vmware.log files starting from Fusion 4: | |||
#!/usr/bin/perl | |||
use strict; | |||
use warnings; | |||
if ($#ARGV != 0) { | |||
print "Recovers .vmx files from .log files. Usage:\n"; | |||
print "$0 logfile > vmxfile\n\n"; | |||
exit; | |||
} | |||
while (<>) { | |||
# Scan until we reach the config section | |||
if (/: DICT --- CONFIGURATION/) { last; } | |||
} | |||
while (<>) { | |||
if (/: DICT --- \S/) { last; } # Keep going until the next section | |||
s/^.*: DICT\s*//; # Strip off the leading timestamp and other stuff | |||
s/\r//; # Get rid of any \r's that may have somehow snuck in | s/\r//; # Get rid of any \r's that may have somehow snuck in | ||
s/([^=]*=) (.*)/$1 "$2"/; # Quote the value | s/([^=]*=) (.*)/$1 "$2"/; # Quote the value |
Latest revision as of 22:10, 25 May 2015
Recover vmx from log file
On the VMware community forums, Eric Tung has devised a little jewel of code that automates recreating a vmx file from a recent vmware.log file.
This is possible as on every boot of a virtual machine, the vmware.log gets a copy from your virtual hardware settings written out into the vmware.log logfile along with some extra information such as the date and time this VM was run. The script extracts the relevant part for you and eliminates the risk of making a typo while doing this by hand. It is written in perl, just a few lines long and shows the true power of what a bit of perl can do for you :)
vmxRecover.pl code
As of Fusion 4, the format of the vmware.log has changed. Here's the script for parsing log files from before Fusion 4
#!/usr/bin/perl use strict; use warnings; if ($#ARGV != 0) { print "Recovers .vmx files from .log files. Usage:\n"; print "$0 logfile > vmxfile\n\n"; exit; } while (<>) { # Scan until we reach the config section if (/: vmx\| DICT --- CONFIGURATION/) { last; } } while (<>) { if (/: vmx\| DICT --- \S/) { last; } # Keep going until the next section s/^.*: vmx\| DICT\s*//; # Strip off the leading timestamp and other stuff s/\r//; # Get rid of any \r's that may have somehow snuck in s/([^=]*=) (.*)/$1 "$2"/; # Quote the value print; }
New version to use for vmware.log files starting from Fusion 4:
#!/usr/bin/perl use strict; use warnings; if ($#ARGV != 0) { print "Recovers .vmx files from .log files. Usage:\n"; print "$0 logfile > vmxfile\n\n"; exit; } while (<>) { # Scan until we reach the config section if (/: DICT --- CONFIGURATION/) { last; } } while (<>) { if (/: DICT --- \S/) { last; } # Keep going until the next section s/^.*: DICT\s*//; # Strip off the leading timestamp and other stuff s/\r//; # Get rid of any \r's that may have somehow snuck in s/([^=]*=) (.*)/$1 "$2"/; # Quote the value print; }
Usage
Say you want to recreate a the virtual hardware configuration for a VMware virtual machine "Windows XP.vmx" then you'd call it like this:
vmxRecover.pl vmware.log > "Windows XP.vmx"
External links
- The original post Not a Valid Virtual Machine Configuration...
- The script vmxRecover.pl.zip
- Eric's site http://www.koiproductions.com