The Blog

XenServer 7.3 Restore VM with CLI

Posted on

Import/Restore a Xen VM from a backed-up image file, likely a backup taken of a VM prior to the destruction of said VM for any reason.

  1. Ensure you have mounted the location with the .xva file. For instance, if it is a remote NFS store, you may want to check the current mount points, or execute:

    mount -t nfs 10.1.1.250:/mnt/backups/xenbackups /mnt/backup
    
  2. Take note of the filename & path that you will use for restoration/import, such as:

    /mnt/backup/Test-VM-2016-02-17_12-23-01.xva
    
  3. If you don’t have shared storage in your Xen Pool, or if you wish to place the VM on a specific server or Storage Repository (SR), execute the command:

    xe sr-list
    

    which will produce output such as this:

                uuid ( RO): 73a394e5-2a60-a13d-9c42-4987d81c1a77
          name-label ( RW): DVD drives
    name-description ( RW): Physical DVD drives
                host ( RO): XEN-SRV-4
                type ( RO): udev
        content-type ( RO): iso
    
                uuid ( RO): 3b3346b2-d08a-90a8-bc13-321e0fe988d9
          name-label ( RW): Removable storage
    name-description ( RW): 
                host ( RO): XEN-SRV-4
                type ( RO): udev
        content-type ( RO): disk
    
                uuid ( RO): 69659292-ca18-3875-8c3b-1c9873db1dc0
          name-label ( RW): Local storage
    name-description ( RW): 
                host ( RO): XEN-SRV-4
                type ( RO): lvm
        content-type ( RO): user
    

    Take note of the uuid of the “Local Storage” of the host on which you wish to place the VM. In this case, if we want to place the VM on “XEN-SRV-4,” then we will need the uuid “69659292-ca18-3875-8c3b-1c9873db1dc0

  4. Using the uuid & filename from above, you can then execute the vm-import command thus, preferably on the physical host where you are importing the VM, to minimize network traffic and potential slowdowns caused by passing packets from one server to another unnecessarily:

    xe vm-import filename=/mnt/backup/Test-VM-2016-02-17_12-23-01.xva sr-uuid=69659292-ca18-3875-8c3b-1c9873db1dc0
    

    If you want or need to retain the VIF MAC addresses (such as for a VM that gets its IP Address via DHCP), ensure that you specify the preserve=true option such as:

    xe vm-import filename=/mnt/backup/Test-VM-2016-02-17_12-23-01.xva sr-uuid=69659292-ca18-3875-8c3b-1c9873db1dc0 preserve=true
    
  5. If you wish to have the VM start automatically when the Hypervisor/Host boots, ensure you re-enable the autostart option, as it does not get restored when importing a VM from a file. For that, you’ll need the uuid of the VM (xe vm-list can help you there) and then you need to execute:

    xe vm-param-set uuid= other-config:auto_poweron=true
    
Posted in XenServer Leave a comment

XenServer 7.3 and NFS

Posted on

Took me all day to figure this out. Xen 7.3 does not come with NFS support oddly. So you need to install it.

First you will surely need the epel repository

yum --enablerepo=extras install epel-release

Now you can install other packages.

yum --enablerepo=epel --enablerepo=base install nfs-utils

I also like MC so let’s install that too.

yum --enablerepo=epel --enablerepo=base install mc

Some useful commends to test NFS.

rpcinfo -s <IP>
showmount -e <IP>
Posted in Virtualization, XenServer Leave a comment

Running multiple instances of MySQL on the same server.

Posted on

Starting point.

Below is another alternative, but this one seems to be a better way to go.

https://www.percona.com/blog/2014/08/26/mysqld_multi-how-to-run-multiple-instances-of-mysql/

Above needs to be done in my.cnf and not the “.d” folders.

Copy /etc/mysql/my.cnf to /etc/mysql/my2.cnf
Also copy conf.d and mysql.conf.d to conf2.d and mysql.conf2.d
Update all the files in them to point to new data location and lock file needs to be in the /tmp/ location.

Pointing to the New Data Location

MySQL has several ways to override configuration values. By default, the datadir is set to /var/lib/mysql in the /etc/mysql/mysql.conf.d/mysqld.cnf file. Edit this file to reflect the new data directory:

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 

Find the line that begins with datadir= and change the path which follows to reflect the new location.

In our case, the updated file looks like the output below:/etc/mysql/mysql.conf.d/mysqld.cnf

. . .
datadir=/var/lib/mysql2
. . .

This seems like the right time to bring up MySQL again, but there’s one more thing to configure before we can do that successfully.

Step 3 — Configuring AppArmor Access Control Rules

We’ll need to tell AppArmor to let MySQL write to the new directory by creating an alias between the default directory and the new location. To do this, edit the AppArmor alias file:

sudo nano /etc/apparmor.d/tunables/alias

At the bottom of the file, add the following alias rule:/etc/apparmor.d/tunables/alias

. . .
alias /var/lib/mysql/ -> /var/lib/mysql2/,
. . .

For the changes to take effect, restart AppArmor:

sudo systemctl restart apparmor

Now we can start new MySQL

shell> mysqld_safe --defaults-file=/etc/mysql/mysql2.cnf &

Posted in Uncategorized Leave a comment
Next Page »