Simple script to take automatic backup of vm for xenserver 7.0
Problem Description
centosuuid=$(cat /root/vmbackup_script/centosuuid)
xe snapshot-uninstall snapshot-uuid=$centosuuid force=true
xe vm-snapshot vm=17fbef36-0a0f-3adc-05b8-59d02457bb9a new-name-label="test_$(date +%b%e)" > /root/vmbackup_script/centosuuid
Working:
we need uuid of of last created snapshot because we want to maintain only one latest snapshot in order to not run out of space for local storage
Our main vm uuid is given by vm=17fbef36-0a0f-3adc-05b8-59d02457bb9a
Conclusion:
This script is not perfect it depends on lot of factor for working properly. Prior testing is a must.
This Simple yet effective solution for taking full backup made my life easier which is one of the main reason for automating things.The next step is for modification of the script to take incremental backup and handel error and xenserver has its own forum giving lot of solution for taking autobackup.
Taking automatic backup of vm is beneficial in the long run and has many advantages in comparison to taking manual backup. This is specially true if you have many vm running and you need to take periodic backup every day or each week,manually doing this kind of task is just monotonous and there will be always chance that you might forget to take a backup.This happens to me a lot, so having most of the vm in xenserver there is always way to do administrative task automatic in xenserver as it is open source it provides lot of command and has good documentation.

Solution:
Use a bash script that combines list of commands to take backup and run it as a cron job
Script:
#!/bin/bashcentosuuid=$(cat /root/vmbackup_script/centosuuid)
xe snapshot-uninstall snapshot-uuid=$centosuuid force=true
xe vm-snapshot vm=17fbef36-0a0f-3adc-05b8-59d02457bb9a new-name-label="test_$(date +%b%e)" > /root/vmbackup_script/centosuuid
Working:
- The first command will write uuid of last snapshot created to a file centosuuid in /root/vmbackup_script/centosuuid
we need uuid of of last created snapshot because we want to maintain only one latest snapshot in order to not run out of space for local storage
- xe snapshot-uninstall and xe vm-snapshot are two main commands that provide argument to run backup using shell ,we are going to use this command and arguments to take a new backup (xe vm-snapshot) while deleting old one (xe snapshot-uninstall) .
- test_$(date +%b%e) will be new name of our snapshot
Our main vm uuid is given by vm=17fbef36-0a0f-3adc-05b8-59d02457bb9a
Conclusion:
This script is not perfect it depends on lot of factor for working properly. Prior testing is a must.
This Simple yet effective solution for taking full backup made my life easier which is one of the main reason for automating things.The next step is for modification of the script to take incremental backup and handel error and xenserver has its own forum giving lot of solution for taking autobackup.
Comments
Post a Comment