Created
August 15, 2013 17:40
-
-
Save kotashiratsuka/6242882 to your computer and use it in GitHub Desktop.
XCP 1.6 discotinued....
but XenServer 6.2 remove VMPP (Virtual Machine Protection Poricy) substitute cron script Example Using # crontab -l 0 * * * * ~/snapshot.sh hourly
0 2 * * * ~/snapshot.sh daily
0 2 * * 0 ~/snapshot.sh weekly
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
#!/bin/bash | |
mode=${1-none} | |
HOURLYBACKUP_TAG="hourlybackup" | |
DAYLYBACKUP_TAG="dailybackup" | |
WEEKLYBACKUP_TAG="weeklybackup" | |
HOURLYBACKUP_LIFETIME="24" | |
DAYLYBACKUP_LIFETIME="30" | |
WEEKLYBACKUP_LIFETIME="1" | |
if [ "$mode" = "hourly" ]; then | |
hbvms=$(for i in $(xe vm-list is-control-domain=false power-state=running --minimal tags:contains=$HOURLYBACKUP_TAG|sed 's/,/ /g'); do xe vm-param-get param-name=name-label uuid=$i; done) | |
#Hourly | |
for vm in $hbvms; do | |
label=hourly-$vm-$(date +%H) | |
oldlabel=hourly-$vm-$(date +%H --date "$HOURLYBACKUP_LIFETIME hours ago") | |
oldsnapshot=`xe snapshot-list name-label=$label --minimal` | |
echo yes | xe snapshot-uninstall snapshot-uuid=$oldsnapshot | |
xe vm-snapshot vm=$vm new-name-label=$label | |
done | |
elif [ "$mode" = "daily" ]; then | |
dbvms=$(for i in $(xe vm-list is-control-domain=false power-state=running --minimal tags:contains=$DAYLYBACKUP_TAG |sed 's/,/ /g'); do xe vm-param-get param-name=name-label uuid=$i; done) | |
#Dayly | |
for vm in $dbvms; do | |
label=daily-$vm-$(date +%d) | |
oldlabel=daily-$vm-$(date +%d --date "$DAYLYBACKUP_LIFETIME days ago") | |
oldsnapshot=`xe snapshot-list name-label=$label --minimal` | |
echo yes | xe snapshot-uninstall snapshot-uuid=$oldsnapshot | |
xe vm-snapshot vm=$vm new-name-label=$label | |
done | |
elif [ "$mode" = "weekly" ]; then | |
wbvms=$(for i in $(xe vm-list is-control-domain=false power-state=running --minimal tags:contains=$WEEKLYBACKUP_TAG|sed 's/,/ /g'); do xe vm-param-get param-name=name-label uuid=$i; done) | |
#Weekly | |
for vm in $wbvms; do | |
label=weekly-$vm-$(date +%d) | |
oldlabel=weekly-$vm-$(date +%d --date "$WEEKLYBACKUP_LIFETIME weeks ago") | |
oldsnapshot=`xe snapshot-list name-label=$label --minimal` | |
echo yes | xe snapshot-uninstall snapshot-uuid=$oldsnapshot | |
xe vm-snapshot vm=$vm new-name-label=$label | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment