{"id":98,"date":"2007-02-06T11:07:00","date_gmt":"2007-02-06T18:07:00","guid":{"rendered":"http:\/\/www.jasemccarty.com\/blog\/2007\/02\/vmware-restoring-custom-attributes-after-a-vc-1x-to-vc-20x-upgrade.html"},"modified":"2007-02-06T11:07:00","modified_gmt":"2007-02-06T18:07:00","slug":"vmware-restoring-custom-attributes-after-a-vc-1x-to-vc-20x-upgrade","status":"publish","type":"post","link":"https:\/\/www.jasemccarty.com\/blog\/vmware-restoring-custom-attributes-after-a-vc-1x-to-vc-20x-upgrade\/","title":{"rendered":"VMware: Restoring Custom Attributes after a VC 1.x to VC 2.0.x upgrade"},"content":{"rendered":"<p>****************************************<br \/>Disclaimer: Keep in mind, this is the process that worked for me, and I don\u2019t recommend that anyone perform this on live data, but rather to test data.  <\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">I am not responsible for any changes to your database as a result of this process.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">If you choose to use this method, please backup your database beforehand.<\/p>\n<p class=\"MsoNormal\">All VC 2.0.x database references are called VirtualCenter and all VC 1.x references are called VirtualCenterOLD.<\/p>\n<p>Also, this properly works with dbo as the owner of all tables.  If you have an alternate owner (as I do) you will have to modify the below scripts to match.<\/p>\n<p class=\"MsoNormal\">****************************************<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">After performing a VC 1.x to VC 2.0.x upgrade, custom attributes are lost.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">This is because the VC 1.x and VC 2.0.x databases handle custom attributes a little different.<span style=\"\">  <\/span>VC 1.x has a custom attributes table called VPX_FIELDDEF, and VMs and HOSTs have separate tables (VPX_VM_FIELDS and VPX_HOST_FIELDS respectively.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">In VC 2.0 there are only 2 tables, VPX_FIELD_DEF and VPX_FIELD_VAL.<span style=\"\">  <\/span><\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">The VC 1.0 table VPX_FIELDDEF is replaced by VPX_FIELD_DEF in VC 2.0.x.<span style=\"\">  <\/span><\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">The VC 1.0 tables, VPX_VM_FIELDS and VPX_HOST_FIELDS are replaced by VPX_FIELD_VAL in VC 2.0.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">To import the old values into the new database, a couple steps will have to be taken.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">Let\u2019s say I have a SQL 2000 database with my VC 2.0.x database named VirtualCenter.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">I need to get to the tables from my old VC 1.x installation.<span style=\"\">  <\/span>So I need to restore the old VC 1.x database where I can get to the data I need.<span style=\"\">  <\/span>So I restore the VC 1.x database to a database (on the same server), with the name VirtualCenterOLD.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">Now run the following script from Query Analyzer, while attached to the new VirtualCenter database:<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p style=\"font-family: courier new;font-family:courier new;\"  class=\"MsoNormal\">USE VirtualCenter<\/p>\n<p style=\"font-family: courier new;font-family:courier new;\"  class=\"MsoNormal\">GO<\/p>\n<p style=\"font-family: courier new;font-family:courier new;\" class=\"MsoNormal\" >INSERT INTO dbo.VPX_FIELD_DEF<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;font-family:courier new;\" class=\"MsoNormal\" >SELECT<span style=\"\">     <\/span>FIELD_ID AS ID, NAME<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;font-family:courier new;\" class=\"MsoNormal\" >FROM<span style=\"\">         <\/span>VirtualCenterOLD.dbo.VPX_FIELDDEF<\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: courier new;font-family:courier new;\" >GO<\/span><\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">This will pull all values from the old VirtualCenterOLD table named VPX_FIELDDEF into the new VirtualCenter database table named VPX_FIELD_DEF, thus defining our custom attribute fields.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">Now, We need to add the data from the Hosts and VMs.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">Now run the following script from Query Analyzer, while attached to the new VirtualCenter database:<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p style=\"font-family: courier new;font-family:courier new;\" class=\"MsoNormal\" >USE VirtualCenter<\/p>\n<p style=\"font-family: courier new;font-family:courier new;\" class=\"MsoNormal\" >GO<\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\" face=\"courier new\">INSERT INTO dbo.VPX_FIELD_VAL<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\" face=\"courier new\">SELECT<span style=\"\">     <\/span>VirtualCenterOLD.dbo.VPX_HOST_FIELDS.FIELD_ID AS FIELD_ID, dbo.VPXV_HOSTS.HOSTID AS ENTITY_ID, <span style=\"\">                      <\/span>VirtualCenterOLD.dbo.VPX_HOST_FIELDS.FIELD_VALUE AS [VALUE]<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\" face=\"courier new\"><o:p> <\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\" face=\"courier new\">FROM<span style=\"\">         <\/span>VirtualCenterOLD.dbo.VPX_HOST LEFT OUTER JOIN<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\" face=\"courier new\"><span style=\"\">       <\/span><span style=\"\">               <\/span>dbo.VPXV_HOSTS ON VirtualCenterOLD.dbo.VPX_HOST.HOSTNAME = dbo.VPXV_HOSTS.NAME LEFT OUTER JOIN<o:p><\/o:p><\/p>\n<p class=\"MsoNormal\" style=\"font-family: courier new;\"><span style=\"\">                      <\/span>VirtualCenterOLD.dbo.VPX_HOST_FIELDS ON VirtualCenterOLD.dbo.VPX_HOST.HOST_ID = VirtualCenterOLD.dbo.VPX_HOST_FIELDS.HOST_ID<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;font-family:courier new;\"  class=\"MsoNormal\">WHERE<span style=\"\">     <\/span>(NOT (VirtualCenterOLD.dbo.VPX_HOST_FIELDS.FIELD_VALUE IS NULL)) AND (NOT (VirtualCenterOLD.dbo.VPX_HOST_FIELDS.FIELD_ID IS NULL))<\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: courier new;font-family:courier new;\" >GO<\/span><\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">This will insert HOST attributes into the VPX_FIELD_VAL, where the FIELD_ID and VALUE come from the old data, and the ENTITY_ID comes from the new Entity value for the ESX Hosts in the new database, making sure that there are no nulls.<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">Now run the following script from Query Analyzer, while attached to the new VirtualCenter database:<\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\">USE VirtualCenter<\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\">GO<\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\">INSERT INTO dbo.VPX_FIELD_VAL<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\">SELECT<span style=\"\">     <\/span>VirtualCenterOLD.dbo.VPX_VM_FIELDS.FIELD_ID AS FIELD_ID, dbo.VPXV_VMS.VMID AS ENTITY_ID, <o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\"><span style=\"\">                      <\/span>VirtualCenterOLD.dbo.VPX_VM_FIELDS.FIELD_VALUE AS [VALUE]<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p style=\"font-family: courier new;font-family:courier new;\"  class=\"MsoNormal\">FROM<span style=\"\">         <\/span>VirtualCenterOLD.dbo.VPX_VM LEFT OUTER JOIN<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;font-family:courier new;\"  class=\"MsoNormal\"><span style=\"\">                      <\/span>dbo.VPXV_VMS ON VirtualCenterOLD.dbo.VPX_VM.NAME = dbo.VPXV_VMS.NAME LEFT OUTER JOIN<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" face=\"courier new\" class=\"MsoNormal\"><span style=\"\">                      <\/span>VirtualCenterOLD.dbo.VPX_VM_FIELDS ON VirtualCenterOLD.dbo.VPX_VM.VM_ID = VirtualCenterOLD.dbo.VPX_VM_FIELDS.VM_ID<o:p><\/o:p><\/p>\n<p style=\"font-family: courier new;\" face=\"courier new\" class=\"MsoNormal\">WHERE<span style=\"\">     <\/span>(NOT (VirtualCenterOLD.dbo.VPX_VM_FIELDS.FIELD_VALUE IS NULL)) AND (NOT (VirtualCenterOLD.dbo.VPX_VM_FIELDS.FIELD_ID IS NULL))<\/p>\n<p face=\"courier new\" class=\"MsoNormal\"><span style=\"font-family: courier new;\">GO<\/span><\/p>\n<p class=\"MsoNormal\"><o:p> <\/o:p><\/p>\n<p class=\"MsoNormal\">This will insert VM attributes into the VPX_FIELD_VAL, where the FIELD_ID and VALUE come from the old data, and the ENTITY_ID comes from the new Entity value for the VM\u2019s in the new database, making sure that there are no nulls.<\/p>\n<p>   This worked well for me, and I didn&#8217;t lose any custom attributes for my 300+ VM&#8217;s or my ESX Hosts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>****************************************Disclaimer: Keep in mind, this is the process that worked for me, and I don\u2019t recommend that anyone perform this on live data, but rather &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-virtualization"],"_links":{"self":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":0,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}