List of VM's with cron

SamTzu

Renowned Member
Mar 27, 2009
527
17
83
Helsinki, Finland
sami.mattila.eu
Has any1 created a cronjob that lists all VM's daily?
Some script that shows something similar than what Proxmox's Datacenter "Search" page does?
(Unfortunately even that won't show you what storage device it was on.)

I'm wondering what to put on that script.
The purpose of that script would be to help with restoration of virtual machines from backup if the host(s) dies.
The problem being that when the host dies there is no record of what was where so the restoration can be somewhat pain full.

What do you guys have to track those with?
I'm thinking something like this...

cat /etc/pve/openvz/* |grep VE_PRIVATE=
VE_PRIVATE="/media/local3/private/102"
VE_PRIVATE="/media/local3/private/103"
VE_PRIVATE="/var/lib/vz/private/116"
VE_PRIVATE="/media/local4/private/121"
VE_PRIVATE="/var/lib/vz/private/140"
VE_PRIVATE="/media/local3/private/145"
VE_PRIVATE="/media/local4/private/190"
VE_PRIVATE="/media/local4/private/194"
VE_PRIVATE="/media/local4/private/195"
VE_PRIVATE="/media/local2/private/400"
VE_PRIVATE="/media/local2/private/401"
VE_PRIVATE="/media/local2/private/404"
VE_PRIVATE="/media/local3/private/406"
VE_PRIVATE="/var/lib/vz/private/411"
VE_PRIVATE="/media/local3/private/444"
VE_PRIVATE="/media/local3/private/445"

cat /etc/pve/qemu-server/* |grep ide
bootdisk: ide0
ide0: local4:172/vm-172-disk-1.qcow2,format=qcow2,size=10G
ide2: none,media=cdrom
bootdisk: ide0
ide0: local3:402/vm-402-disk-1.qcow2,format=qcow2,size=32G
ide2: none,media=cdrom

Then pipe those to a log file somewhere.

Comments?
 
PS. It would not be too difficult to (backup) restore ALL VM's from a host that had a drive failure with 1 command using that script. :)
Or think about 1 command full migration of ALL VM's from host2host :)
 
Last edited:
This is what I put on crontab -e.

00 01 * * * /bin/date && /bin/cat /etc/pve/openvz/* |grep VE_PRIVATE= >> /var/log/pve/vmlistvz.log
00 02 * * * /bin/date && /bin/cat /etc/pve/qemu-server/* |grep ide >> /var/log/pve/vmlistqemu.log

Let me know if you have better idea.
 
[..]Or think about 1 command full migration of ALL VM's from host2host :)
I have this script which does this for all running VM's on a node:
cat maintainance_mode.sh
Code:
#!/bin/bash
if [ -z $1 ] ; then
 echo "usage: $0 <target-node> [offline]"
 echo "       Migrate all running CTs and VMs on local node to target node."
 echo "       Online- (Live-)migration is default."
 echo "       In case live migration fails, please try offline mode."
 exit
fi

if [ ! -d /etc/pve/nodes/$1 ] ; then
 echo "Target node $1 does not exist!"
 exit 1
fi

ping -c 2 -W 2 $1 >/dev/null 2>&1
if [ $? != 0 ] ; then
 echo "node $1 is not reachable."
 exit 1
fi

if [ "x$2" == "xoffline" ] ; then
 OPT=""
else
 OPT="-online"
fi

for OVZ in $(pvectl list|grep running|awk '{print $1}'); do
  echo "Migrating OVZ: $OVZ to $1..."
  pvectl migrate $OVZ $1 $OPT
  echo "$OVZ done."
done

for KVM in $(qm list|grep running|awk '{print $1}'); do
  echo "Migrating KVM: $KVM to $1..."
  qm migrate $KVM $1 $OPT
  echo "$KVM done."
done
 
  • Like
Reactions: 1 person

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!