Jump to content

Backup script to backup a running KVM VM, and archive the backup with 7Zip.


colincoates

Recommended Posts

Hi Everyone,

This is my first post, so be gentle on me  :)

 

I've been using Unraid for the best part of 2 years now, and I love it.

After moving to v6 and adopting Xen, I was even more impressed (I had been using the Virtualbox plugin to run a few VMs in v5 and found it really unpredictable)

I got a bit of a fright when I saw that Xen was being dropped, and reluctantly started to migrate to KVM - I'm glad I did, it does everything that I need and after quite a bit of google-fu I managed to get a working process to backup running VMs...

 

I put together this script in Powershell, mainly because I can find my way around PS. I've got very little experience with shell scripts and my 'Nix skills leave a bit to be desired.

 

A quick summary of what it does:

 

It will read the configuration from a CSV file. Things like the VM name, the disk path, how many days, weeks, months to keep backups.

It will then use plink to:

    ssh to unraid and take a snapshot of a running VM.

    Make a copy of the disk file

    Recommit the snapshot back into the running VM and delete the snapshot.

It will then use 7Zip to compress the disk file and save it to an archive. If there are more than the specified Days,Weeks,Months of backups in the archive it will delete the oldest on the the set.

 

It requires either p7zip to be installed on unraid, or 7zip installed on the windows machine it is running on (I've commented out the options for the windows 7Zip)

 

I got the 64 bit version 9.20.1 of p7zip from slackware.org.uk and installed it like this.

wget -O http://slackware.org.uk/slacky/slackware64-14.1/system/p7zip/9.20.1/p7zip-9.20.1-x86_64-1sl.txz

#move it to /boot/extra to install on boot - Thanks Trurl

mv p7zip-9.20.1-x86_64-1sl.txz /boot/extra/

installpkg p7zip-9.20.1-x86_64-1sl.txz

 

I've left my configuration as an example in the CSV file, you would need to change it to your own configuration.

I also had some trouble with plink to start off with, if you run it from cmd and open a connection to the unraid box it will save the ssh keys and work from then on.

 

This is still a work in progress, and I'll update it as and when I get time (a rare commodity at the moment)

 

I'm using:

HP Microserver N54L

4GB RAM (tempted to up to 16, but don't really need it yet)

3x HGST 4TB 7200 RPM disks (one is parity)

2x Samsung 1.5TB 5400 RPM disks (slowly replacing these)

2x HGST 500GB 7200 RPM disks in BTRFS Cache pool

 

I am open to, and would welcome any feedback and suggestions.

Thanks,

CC

backup_kvm_v0.3.ps1.zip

Link to comment

Not running any VMs at the moment so won't be trying this soon. Just thought I would give some advice on installing the package.

 

unRAID will automatically installpkg anything in /boot/extra when it boots so that is an easy way to get it reinstalled on boot instead of doing it in go.

Link to comment

Not running any VMs at the moment so won't be trying this soon. Just thought I would give some advice on installing the package.

 

unRAID will automatically installpkg anything in /boot/extra when it boots so that is an easy way to get it reinstalled on boot instead of doing it in go.

 

Thanks, I've updated my original post.

Link to comment
  • 8 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...