/xen_backup

Xen backup

Primary LanguageShell

Xen backup

Xen backup to external HDD or SMB share

How it works

  1. Create SNAPSHOT
  2. Convert to TEMPLATE
  3. Export to .xva file (to external USB HDD or SMB share)
  4. Delete SNAPSHOT
  5. Delete backups older than 10 days

Prepare xen-uuids.txt

  • SSH to host
  • Type "xe vm-list" to show UUIDs of virtual machines for backup
  • Put UUIDs to /home/xen-backup/xen-uuids.txt
  • Type "Enter" after last UUID

Example xen-uuids.txt

2a120389-80fe-2ade-380e-65733c4a563d
c096ed53-4f29-722c-2790-1b7a2a71ff4d

Backup to external HDD

  • Plug external USB HDD
  • "fdisk -l" to show all disks.
  • Find your disk (e.g. "sdc")
  • Mount disk - "mount /dev/sdc1 /mnt/hdd"
  • Change values in xen-backup-hdd.sh
    UUIDFILE=./xen-uuids.txt
    BACKUPPATH=/mnt/hdd
    
  • Run ".\xen-backup-hdd.sh"
  • Unmout disk - "umount /mnt/hdd"

Backup to SMB share

  • Change values in xen-backup-smb.sh
    UUIDFILE=./xen-uuids.txt
    SERVER=//192.168.1.99
    UNC=share/xen_backup
    MOUNTPOINT=/mnt/mount_point
    mount.cifs ${SERVER}/${UNC} ${MOUNTPOINT} -o username=USERNAME,password=SECRETPASSWORD
    
  • Run ".\xen-backup-smb.sh"

Cron it

Backup to USB HDD at 23:00 everyday, and to SMB share at 01:00.

/var/spool/cron/root

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

0 23 * * * cd /home/xen-backup && /bin/bash xen-backup-hdd.sh
0 1 * * * cd /home/xen-backup && /bin/bash xen-backup-smb.sh

Restore VM

xe vm-import filename=/mnt/hdd/<name_of_VM.xva> force=true preserve=true

Set "preserve" to "false" if you need to duplicate VM.

Be careful with symbols in the name of .xva file.