Skip to main content

How to reset cluster configuration in Proxmox 2

If you have already made the proxmox cluster, but you want to make changes to the cluster config, for example for changing the hostname of the node, or the network with which the nodes are communicating on in the cluster, you can remove the cluster and create it again:

First, make a backup of the cluster:

cp -a /etc/pve /root/pve_backup

Stop cluster service:

/etc/init.d/pve-cluster stop

Umount /etc/pve if it is mounted:

umount /etc/pve

Stop corosync service:

/etc/init.d/cman stop

Remove cluster configuration:

# rm /etc/cluster/cluster.conf
# rm -rf /var/lib/pve-cluster/*

Start again cluster service:

/etc/init.d/pve-cluster start

Now, you can create new cluster:

# pvecm create newcluster 

Restore cluster and virtual machines configuration from the backup:

# cp /root/pve_backup/*.cfg /etc/pve/
# cp /root/pve_backup/qemu-server/*.conf /etc/pve/qemu-server/
# cp /root/pve_backup/openvz/* /etc/pve/openvz/

UPDATE: This post is also valid to change the hostname of a node in a cluster or to move a node between two clusters. When you have removed a node from the cluster, it still appears in the proxmox nodes tree, to remove it from the tree you have to delete the node directory from another node in the cluster:

# rm -rf /etc/pve/nodes/HOSTNAME

KVM/Openvz dumps with specific name using a hook

Vzdump is the tool used to back up virtual machines in Proxmox.
A few weeks ago, I wrote an entry describing how to do a dump with an specified name, rather than using the default naming for this backups in Creating Kvm backups with an specific name, but now, I’m comming with a much more elegant solution using a hook for vzdump. In Proxmox 2.x, you can back up machines from the web interface very easily and using a hook all is done transparently.

This tool has an option “-script” to be able to call an script during its execution.

 -script    string
	     Use specified hook script.

You can configure an script to do what ever you want in diferent states during vzdump execution. In this case, I only want to rename default file to a more representative one so I’ve only used the backup-end state to do it at the end of the dump process. My script located in /root/scripts/vzdump-hook-script.pl:

#!/usr/bin/perl -w

# example hook script for vzdump (--script option)

use strict;
use File::Copy qw(move);

my $basedir="/mnt/pve/pve-backups/dump";
print "HOOK: " . join (' ', @ARGV) . "\n";

my $phase = shift;
if ($phase eq 'backup-end' ){
    my $mode = shift; # stop/suspend/snapshot
    my $vmid = shift;
    my $vmtype = $ENV{VMTYPE} if defined ($ENV{VMTYPE}); # openvz/qemu
    my $dumpdir = $ENV{DUMPDIR} if defined ($ENV{DUMPDIR});
    my $hostname = $ENV{HOSTNAME} if defined ($ENV{HOSTNAME});
    # tarfile is only available in phase 'backup-end'
    my $tarfile = $ENV{TARFILE} if defined ($ENV{TARFILE});
    # logfile is only available in phase 'log-end'
    my $logfile = $ENV{LOGFILE} if defined ($ENV{LOGFILE});
    print "HOOK-ENV: vmtype=$vmtype;dumpdir=$dumpdir;hostname=$hostname;tarfile=$tarfile;logfile=$logfile\n";
    if ($phase eq 'backup-end' and defined ($tarfile) and defined ($hostname)) {
        if ( $tarfile=~/($basedir\/vzdump-(qemu|openvz)-\d+-)(\d\d\d\d_.+)/ ){
          my $tarfile2=$1.$hostname."-".$3;
          print "HOOK: Renaming file $tarfile to $tarfile2\n";
          move $tarfile, $tarfile2;
        }
    }
}

exit (0);

 

With this script you get a file name like vzdump-qemu-106-HOSTNAME-2012_06_22-14_35_59.tar.gz and this files are correctly listed by Proxmox interface. You can check the sample script /usr/share/doc/pve-manager/examples/vzdump-hook-script.pl to view all available states.

Configure the script in /etc/vzdump.conf

# vzdump default settings

#tmpdir: DIR
#dumpdir: DIR
#storage: STORAGE_ID
#mode: snapshot|suspend|stop
#bwlimit: KBPS
#ionice: PRI
#lockwait: MINUTES
#stopwait: MINUTES
#size: MB
#maxfiles: N
script: /root/scripts/vzdump-hook-script.pl
#exclude-path: PATHLIST

Now, every vzdump execution will call our script to rename the dump file name.
To finish you only have to apply this changes to all nodes in the Proxmox cluster.

vzdump: create KVM backups with an specific name

With Proxmox VE, the virtual environment I am using, you can configure KVM backups, but you are going to get dump files like this:

vzdump-qemu-117-YYYY_MM_DD-HH_MM_SS.tgz

The names of these files are not very representative and you should rename them if you want to easily identify your KVM backups in your storage.

I am using this command for KVM backups to get the files with their server names:

#
# vzdump --compress  --snapshot --storage pve-backups --maxfiles 2 --stdout 117 > /mnt/pve/pve-backups/myserver_YYYY_MM_DD.tgz
# 

You can put this command in a cron if you want.

To restore the machine simply run:

#
# qmrestore /mnt/pve/pve-backups/myserver_YYYY_MM_DD.tgz 117
#

Notice: Undefined variable: wp_sh_class_name in /var/www/elkano.org/blog/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002

Notice: Undefined variable: wp_sh_class_name in /var/www/elkano.org/blog/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1002

Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /var/www/elkano.org/blog/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048