Un petit script qui peut servir, en fonction de ce post-ci: Installer Xen
#! /bin/bash
#
# Description:
# ------------
#
# Script interactif de sauvegarde pour machine virtuelle Xen.
#
#####################################
# Dernière modification - 2008.03.22
#####################################
# Variables connues
VMS=$(find /etc/xen -type f | grep [*.cfg]$ )
# Chemin du fichier
printf "================================================\n"
printf "Quel est le chemin du fichier de configuration ?\n"
printf "================================================\n\n\n"
printf "Les fichiers trouvés dans /etc/xen:\n"
printf "$VMS \n"
read path_vm
if [[ `ls "$path_vm" ` != "$path_vm" ]];
then
printf "Le chemin spécifié n'existe pas\n"
exit 3
fi
if [ ! `echo -n "$path_vm" | grep "cfg$"` ];
then
printf "\nVous devez entrer un chemin valide !\n"
printf "Les fichiers disponible(s) se trouve dans /etc/xen/ par défaut\n"
printf "\n"
printf "`ls /etc/xen/ `\n";
exit 3
else
printf "Le chemin est ' "$path_vm" ' \n\n"
fi
# Nom de la machine
printf "================================================\n"
printf "Le nom de la machine à sauvegarder ?\n"
printf "================================================\n\n\n"
printf "Les machines en cours de fonctionements:\n"
printf "`xm list | grep ^[^Name*] | grep ^[^D*]`\n"
printf "\n\n Les machines potentiellement opérationnelles: \n"
printf "`echo -n "$VMS" | grep [*.cfg]$ | cut -d/ -f4 | cut -d. -f1`\n"
read name_vm
if [[ ! `echo -n "$name_vm"` ]];
then
printf "\n Vous devez entrer un nom !\n\n\n"
printf "La/Les Machine(s) disponible(s)\n"
printf "\n"
printf "`xm list` \n"
exit 3
fi
# Nom du volume groupe ( LVM )
printf "================================================\n"
printf "Quel est le chemin du disque ?\n"
printf "================================================\n"
printf "\t ( Volumes logique seulement (LVM) )\n\n\n"
printf "Liste des volumes logiques:\n"
printf "`lvdisplay | grep LV | grep Name | awk -F " " '{print$3}'`\n"
read path_lv
path_lv=`echo "$path_lv" | sed -e 's/^\ //g'`
if [[ ! ` echo -n "$path_lv" ` ]];
then
printf "\n Le chemin est vide ! \n\n\n"
printf "Le(s) volume(s) logique(s) disponible(s) : \n"
printf "`lvdisplay | grep $name_vm` \n"
exit 3
fi
# Redémarrage de la machine virtuelle après l'opération
printf "Voulez-vous redémarrer la machine virtuelle après le backup"
printf "(Oui/Non)O/N ? :"
read resp_on
resp=`echo $resp_on | tr [":upper:"] [":lower:"]`
if [[ ! `echo $resp | grep "[o\|n]\|[oui\|non]" ` ]];
then
printf "Vous devez répondre par Oui/Non !\n"
exit 3
fi
# Variable date
date=$(date)
date_c=$(date +%F)
# On lance le back up
printf "\n\n\n==============================\n"
printf " BACKUP starting ...\n"
printf "==============================\n\n\n"
printf "Il est $date \nLe backup commence dans 30 secondes\n\n\n\n\n"
sleep 30s
printf "Wait...\n\n\n\n\n"
if [[ ! `xm list | grep $name_vm | cut -d\ -f1` ]];
then
`dd if=$path_lv of=/home/$name_vm-bkp-$date_c.img bs=1M `
else
xm shutdown $name_vm && sleep 20s && dd if=$path_lv of=/home/$name_vm-bkp-$date_c.img bs=1M
fi
# Redémarrage ?
if [ `echo -n "$resp" | cut -c1` = "o" ];
then
xm create $path_vm
printf "\n\n\n=========================================================================\n"
printf "\tBack up fini à $date\n"
printf "=========================================================================\n"
else
printf "\n\n\n=========================================================================\n"
printf "\tBack up fini à $date\n"
printf "=========================================================================\n"
fi
exit