Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 2659  / 2 Years ago, mon, february 21, 2022, 11:35:27

I have an ubuntu 10.04 server running my VMs on kvm/qemu.
I've been manually pausing my VMs (using virt-manager gui) and then copying the /var/lib/libvirt folder to an external usb drive at /mnt/usbexterno
This obviously is far from ideal.
I need a solution to run a backup everynight.



I thougt about using a cron job with a script to pause the VMs and copy the files to the drive.
I've read on a forum that I could use virsh to save the VM state to a file, but I dont think thats what I need, since I want a full backup of everything in case the server goes boom!



So, short version. I need something to run a daily backup of my VMs to an external usb drive, the VMs can be paused during the night. Theres no GUI available on the server.



Any suggestions ?


More From » server

 Answers
0

Took me a while to get back to this, sorry to everyone that gave me tips.
Here's the solution I ended up with.



Since I still didnt really grasp the snapshot/restore snapshot concept (yes I am kinda thick headed), I made a script to delete old files, starting from the link that Michael K provided, then proceeded to making a folder with todays date on the usb drive, pausing all active VMs (absolutely no need for 100% uptime here, company runs 9am-6pm), and copying all of /var/lib/libvirt in there, and then resume VMs and be happy.



Here is the script.



#!/bin/bash

find /mnt/usbexterno/backup* -maxdepth 0 -type d -mtime +15 -exec rm -rf {} ;

virsh list | sed '1,2d' | cut -d' ' -f3>/tmp/vmlist

VMLIST=$(cat /tmp/vmlist)
set -- $VMLIST
for i in $VMLIST
do
/usr/bin/virsh suspend $1
shift
done

mkdir /mnt/usbexterno/`date +backup-%Y-%m-%d`
cp -Rv /var/lib/libvirt /mnt/usbexterno/`date +backup-%Y-%m-%d`

set -- $VMLIST
for i in $VMLIST
do
/usr/bin/virsh resume $1
shift
done
rm /tmp/vmlist


If anybody has any tips on how I could improve this please be my guest :D


[#41383] Tuesday, February 22, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wherejuic

Total Points: 53
Total Questions: 123
Total Answers: 117

Location: Zambia
Member since Mon, Jan 23, 2023
1 Year ago
wherejuic questions
Thu, Aug 19, 21, 18:07, 3 Years ago
Wed, May 12, 21, 03:23, 3 Years ago
Sat, Nov 13, 21, 05:27, 3 Years ago
Mon, Sep 5, 22, 17:36, 2 Years ago
;