Code Monkey home page Code Monkey logo

backup-vm's Introduction

backup-vm

Back up your libvirt-based VMs using Borg!

Features

  • Backup running VMs
    • Automatically creates a COW snapshot of virtual disks to avoid corruption and pivots them back afterwards
    • From the perspective of the VM, restoring from a live backup is like a sudden power-off
      • Chances of file corruption are still low with a guest agent installed
  • Can back up multiple VM disks
    • Supports disk images backed by a file or a block device
  • Can back up to multiple Borg repositories at once
    • Only one snapshot operation needed for multiple backups
    • Auto-answers subsequent prompts from other borg processes
    • Shows total backup progress % (even with multiple backups)
  • Pass extra arguments straight to Borg on the command line
    • Different settings (e.g. compression) can be passed to each instance

Examples

Backup

Back up a virtual machine to a single Borg repo:

backup-vm myVM myrepo::myBackup

Back up a virtual machine webserver to an onsite and an offsite Borg repository with varying compression settings:

backup-vm webserver onsite::webserver-{now:%Y-%m-%d} --borg-args --compression lz4 offsite::webserver-{now:%Y-%m-%d} --borg-args --compression zlib,9

Back up only the system drive of a Windows VM:

backup-vm win10 sda myrepo::win10-{now:%Y-%m-%d}

Restore

A script for automatic restoration is in development; however, the backups are saved with a simple directory structure that makes manual restoration easy. Each backup has the image of each disk clearly named in the root directory (e.g. sda.raw, hdb.qcow2). The legacy bash script for restoring follows a similar process to what the Python version will, with the notable exception that it does not handle multiple disks.

Usage

usage: backup-vm [-hpv] domain [disk [disk ...]] archive
    [--borg-args ...] [archive [--borg-args ...] ...]

Back up a libvirt-based VM using borg.

positional arguments:
  domain           libvirt domain to back up
  disk             a domain block device to back up (default: all disks)
  archive          a borg archive path (same format as borg create)

optional arguments:
  -h, --help       show this help message and exit
  -v, --version    show version of the backup-vm package
  -p, --progress   force progress display even if stdout isn't a tty
  --borg-args ...  extra arguments passed straight to borg
usage: borg-multi [-hpv] [--path PATH] [--borg-cmd SUBCOMMAND]
    archive [--borg-args ...] [archive [--borg-args ...] ...]

Batch multiple borg commands into one.

positional arguments:
  archive          a borg archive path (same format as borg create)

optional arguments:
  -h, --help       show this help message and exit
  -v, --version    show version of the backup-vm package
  -l, --path       path for borg to archive (default: .)
  -p, --progress   force progress display even if stdout isn't a tty
  -c, --borg-cmd   alternate borg subcommand to run (default: create)
  --borg-args ...  extra arguments passed straight to borg

Installation

Python โ‰ฅ3.4 is required, as well as the Python libvirt bindings. If possible, install them from the system package manager (apt install python3-libvirt); otherwise, use pip (pip install libvirt-python). To install the script, copy it into /usr/local/bin and optionally remove the .py extension.

For offline backups, qemu-img is required, although it is normally installed along with libvirt.

backup-vm's People

Contributors

milkey-mouse avatar m-beno avatar rugk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.