diff --git a/README.rst b/README.rst index bee0583..3a147cd 100644 --- a/README.rst +++ b/README.rst @@ -101,6 +101,23 @@ Usage .. END AUTO-GENERATED USAGE +Building +-------- + +Example of how the binary is built, based on Debian Bullseye. + +:: + + git clone https://github.com/milkey-mouse/backup-vm.git + cd backup-vm + sudo apt-get install python3-pip python3-setuptools python3-libvirt + python3 setup.py build + sudo python3 setup.py install + +:: + +The binary ``backup-vm`` will now exist in ``/usr/local/bin/``. + Installation ------------ diff --git a/backup_vm/backup.py b/backup_vm/backup.py index a2613fd..837113b 100755 --- a/backup_vm/backup.py +++ b/backup_vm/backup.py @@ -2,6 +2,8 @@ import os.path import sys +import subprocess +import platform import libvirt from . import parse from . import multi @@ -46,8 +48,27 @@ def main(): for archive in args.archives: archive.extra_args.append("--read-special") + # dump the xml before the snapshot so that we have the original disk devices + dom_xml = dom.XMLDesc(0) + with snapshot.Snapshot(dom, all_disks, args.progress), \ builder.ArchiveBuilder(disks_to_backup) as archive_dir: + + f = open("origin.txt", "w") + f.write(platform.node()) + f.close() + + f = open(args.domain + ".xml", "w") + f.write(dom_xml) + f.close() + + for disk in all_disks: + if disk in disks_to_backup and disk.type == "dev": + lv = subprocess.check_output(["/usr/sbin/lvdisplay", disk.path], text=True) + f = open( (disk.path + ".lv")[1:].replace("/", "--"), "w" ) + f.write(lv) + f.close() + if args.progress: borg_failed = multi.assimilate(args.archives, archive_dir.total_size) else: