Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
403ca3e
commit 14c5026
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BACKUP=/backup | ||
DEVICE=/dev/mapper/XSLocalEXT--fc65c3f6--d3eb--ae4e--ce4a--7eb58998ff10-fc65c3f6--d3eb--ae4e--ce4a--7eb58998ff10 | ||
BACKUP_DIR=$BACKUP/vms | ||
NOTIFICACION="yourmail@mail.com" | ||
VMS="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/bin/bash | ||
WORKSPACE=/backup/scripts | ||
. $WORKSPACE/bin/backup2.cfg | ||
|
||
|
||
rm -f $BACKUP/vms/* | ||
|
||
# Redireccionar salida y errores | ||
exec > $WORKSPACE/log/backup3.log 2>&1 | ||
echo "--------------------------------------------------" | ||
echo "Beginning backup of virtual machines at $(date)" | ||
echo "--------------------------------------------------" | ||
|
||
ERR=0 | ||
|
||
#Getting VM uuid list | ||
xe vm-list --minimal | sed s/','/'\n'/g > vm_list | ||
|
||
#Search CustomField.Backup | ||
for uuid in `cat vm_list` ; do | ||
backup_vm=`xe vm-param-get uuid=$uuid param-name=other-config param-key=XenCenter.CustomFields.Backup` | ||
if [ "$backup_vm" == "s" ] ; then | ||
vm_name=`xe vm-list uuid=$uuid params=name-label | cut -f2 -d":" | cut -f2 -d" "` | ||
echo $vm_name ' - Marked for backup' | ||
|
||
# uuid=$(xe vm-list params=uuid name-label=$vm_name --minimal) | ||
echo "Beginning backup of $vm_name @ $(date)" | ||
|
||
echo "Taking a snapshot of: $vm_name" | ||
snapshotUUID=$(xe vm-snapshot vm=$uuid new-name-label=backup_vm) | ||
echo "Snapshot: $vm_name created" | ||
|
||
echo "Turning $vm_name snapshot into a vm" | ||
xe template-param-set is-a-template=false ha-always-run=false uuid=$snapshotUUID | ||
|
||
echo "Exporting: $vm_name" | ||
exportstring=$BACKUP_DIR/$vm_name.xva-$(date +%d%m%y) | ||
xe vm-export vm=$snapshotUUID filename=$exportstring compress=true | ||
|
||
if [ $? -eq 0 ] ; then | ||
echo "Sin problemas" | ||
else | ||
ERR=1 | ||
fi | ||
|
||
echo "Done, Removing snapshot: $vm_name" | ||
xe vm-uninstall uuid=$snapshotUUID force=true | ||
|
||
echo "Completed backup of $vm_name @ $(date)" | ||
echo "--------------------------------------------------" | ||
echo | ||
|
||
else | ||
echo 'no hay backup' | ||
fi | ||
done | ||
|
||
echo "Backup completed at $(date)" | ||
if [ $ERR -eq 0 ] | ||
then | ||
ASUNTO="OK Backup VM XENBOX - $(uname -n)" | ||
else | ||
ASUNTO="ERROR Backup VM XENBOX - $(uname -n)" | ||
fi | ||
|
||
echo $ASUNTO | ||
echo Finalizamos - $(date) | ||
LOGPROC=`/usr/bin/tail -100 /backup/scripts/log/backup3.log` | ||
|
||
cat /backup/scripts/log/backup3.log | mail -s "$ASUNTO" maail@mail.com | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Insert VMLIST to initializate the XAPI Backup CustomField | ||
VMLIST="" | ||
|
||
for vm in $VMLIST; do | ||
uuid=$(xe vm-list name-label=$vm --minimal) | ||
xe vm-param-set uuid=$uuid other-config:XenCenter.CustomFields.Backup='s' | ||
done |
Empty file.