virt-back


Namevirt-back JSON
Version 0.2.4 PyPI version JSON
download
home_pagehttps://git.unturf.com/python/virt-back
Summaryvirt-back: A backup utility for QEMU, KVM, XEN, and Virtualbox guests
upload_time2024-07-08 12:54:16
maintainerNone
docs_urlNone
authorRussell Ballestrini
requires_pythonNone
licensePublic Domain
keywords backup virtual hypervisor qemu kvm xen virtualbox
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            A backup utility for QEMU, KVM, XEN, and Virtualbox guests.

Virt-back is a python application that uses the libvirt api to safely 
shutdown, gzip, and restart guests.  The backup process logs to syslog
for auditing and virt-back works great with cron for scheduling outages.
Virt-back has been placed in the public domain and 
the latest version may be downloaded here:

https://git.unturf.com/python/virt-back


**usage**

```
virt-back --help
usage: virt-back [-h] [-q] [-d] [-g] [-a amount] [-p 'PATH'] [-u 'URI'] [-i] [--info-all] [-b] [-r] [-s] [-c] [--backup-all] [--reboot-all] [--shutdown-all] [--create-all]

A backup utility for QEMU, KVM, XEN, and Virtualbox guests. Virt-back is a python application that uses the libvirt api to safely shutdown, gzip, and restart guests. The backup process
logs to syslog for auditing and virt-back works great with cron for scheduling outages. Virt-back has been placed in the public domain and the latest version may be downloaded here:

https://git.unturf.com/python/virt-back

options:
  -h, --help            show this help message and exit
  -q, --quiet           prevent output to stdout
  -d, --date            append date to tar filename [default: no date]
  -g, --no-gzip         do not gzip the resulting tar file
  -a amount, --retention amount
                        backups to retain [default: 3]
  -p 'PATH', --path 'PATH'
                        backup path [default: '/KVMBACK']
  -u 'URI', --uri 'URI'
                        optional hypervisor uri

Actions for info testing:
  These options display info or test a list of guests.

  -i, --info            info/test a list of guests (space delimited dom names)
  --info-all            attempt to show info on ALL guests

Actions for a list of dom names:
  WARNING: These options WILL bring down guests!

  -b, --backup          backup a list of guests (space delimited dom names)
  -r, --reboot          reboot a list of guests (space delimited dom names)
  -s, --shutdown        shutdown a list of guests (space delimited dom names)
  -c, --create          start a list of guests (space delimited dom names)

Actions for all doms:
  WARNING: These options WILL bring down ALL guests!

  --backup-all          attempt to shutdown, backup, and start ALL guests
  --reboot-all          attempt to shutdown and then start ALL guests
  --shutdown-all        attempt to shutdown ALL guests
  --create-all          attempt to start ALL guests
```


## Dependencies

Before installing `virt-back`, you need to ensure that the necessary development libraries for `libvirt` are installed on your system. These libraries are required for the `libvirt-python` package, which `virt-back` depends on.

### Fedora/RedHat

On Fedora or RedHat-based systems, you can install the `libvirt-devel` package using `dnf`:

```bash
sudo dnf install libvirt-devel
```

### Ubuntu/Debian

On Ubuntu or Debian-based systems, you can install the `libvirt-dev` package using `apt-get`:

```bash
sudo apt-get install libvirt-dev
```

### Installing `virt-back`

Once the necessary development libraries are installed, you can install `virt-back` using `pip`:

```bash
pip install virt-back
```

This will install `virt-back` along with its dependencies, including `libvirt-python`.


## How to backup zfs snapshot all KVM instances on a TrueNAS Scale, 

```
root@guile[/mnt/downloads/virt-back]# ./virt-back -u "qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock" --backup-all --path /mnt/personal/backup/virt-back --no-gzip --retention 5

shutdown: invoking shutdown on 1_akuma
shutdown: waited 0 seconds for 1_akuma to shut off
backup: invoking backup for 1_akuma
backup: checking if /dev/zvol/downloads/akuma-tfjpo7 is a ZFS dataset
backup: downloads/akuma-tfjpo7 is a ZFS dataset
backup: creating ZFS snapshot downloads/akuma-tfjpo7@backup-2024-07-07-2 for 1_akuma
backup: sending ZFS snapshot downloads/akuma-tfjpo7@backup-2024-07-07-2 to /mnt/personal/backup/virt-back/1_akuma-2024-07-07.zfs for 1_akuma
backup: skipping ISO file /mnt/downloads/iso/ubuntu-24.04-live-server-amd64.iso for 1_akuma
create: invoking create on 1_akuma
backup: rotating backup files for 1_akuma
backup: archiving files for 1_akuma to /mnt/personal/backup/virt-back/1_akuma.tar
backup: archiving /mnt/personal/backup/virt-back/1_akuma.xml for 1_akuma
backup: checking if /dev/zvol/downloads/akuma-tfjpo7 is a ZFS dataset
backup: downloads/akuma-tfjpo7 is a ZFS dataset
backup: archiving /mnt/personal/backup/virt-back/1_akuma-2024-07-07.zfs for 1_akuma
backup: finished backup for 1_akuma
```

## Restoring from a ZFS Backup

This section explains how to restore a KVM instance from a ZFS backup using the `virt-back` utility. The process involves extracting the backup archive, restoring the ZFS snapshot, and creating a new VM in TrueNAS Scale using the restored ZFS volume.

### Step-by-Step Restore Process

1. **Extract the Backup Archive**: Extract the tar archive to get the ZFS snapshot file and the XML configuration file.
2. **Restore the ZFS Snapshot to a New Dataset**: Use the `zfs receive` command to restore the ZFS snapshot to a new dataset.
3. **Create a New VM in TrueNAS Scale**: Use the TrueNAS Scale UI to create a new VM and point it to the restored ZFS volume.

### Detailed Steps

#### 1. Extract the Backup Archive

First, extract the tar archive to get the ZFS snapshot file and the XML configuration file. Use the `--strip-components` option to remove the leading directory components if necessary.

```bash
tar -xvf /mnt/personal/backup/virt-back/1_akuma.tar --strip-components=4 -C /mnt/personal/backup/virt-back
```

This command will extract the files directly to the `/mnt/personal/backup/virt-back` directory, removing the leading directory components.

#### 2. Restore the ZFS Snapshot to a New Dataset

Use the `zfs receive` command to restore the ZFS snapshot to a new dataset. Assuming the extracted ZFS snapshot file is named `1_akuma-2024-07-07.zfs`:

```bash
zfs receive -F downloads/akuma-tfjpo7-restored < /mnt/personal/backup/virt-back/1_akuma-2024-07-07.zfs
```

This command will restore the ZFS snapshot to the `downloads/akuma-tfjpo7-restored` dataset.

#### 3. Create a New VM in TrueNAS Scale

1. **Open TrueNAS Scale UI**: Log in to the TrueNAS Scale web interface.
2. **Navigate to Virtual Machines**: Go to the "Virtual Machines" section.
3. **Create a New VM**:
   - Click on "Add" to create a new VM.
   - Fill in the necessary details for the new VM (e.g., name, CPU, memory).
4. **Attach the Restored ZFS Volume**:
   - In the "Disks" section, add a new disk.
   - Select "Existing Zvol" and choose the restored ZFS volume (`downloads/akuma-tfjpo7-restored`).
5. **Complete the VM Creation**: Finish the VM creation process by following the remaining steps in the UI.

### Summary

By following these steps, you can restore the ZFS snapshot and reattach it to a new VM using the TrueNAS Scale UI. This process involves extracting the backup archive, restoring the ZFS snapshot to a new dataset, and creating a new VM in TrueNAS Scale, pointing it to the restored ZFS volume. This approach ensures that the original dataset remains unaffected and allows you to easily restore and reattach your KVM instances. It's similar to cloning an existing instance except it's from a file backup so the machine will have all the attributes of the clone don't start them both at the same time because that would have IP address overlaps etc.

            

Raw data

            {
    "_id": null,
    "home_page": "https://git.unturf.com/python/virt-back",
    "name": "virt-back",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "backup virtual hypervisor QEMU KVM XEN Virtualbox",
    "author": "Russell Ballestrini",
    "author_email": "russell@ballestrini.net",
    "download_url": "https://files.pythonhosted.org/packages/13/0a/c61c4fa525d8e4561c2e9e642edc858e04ba46a7a5d505ccd48ad152e44a/virt-back-0.2.4.tar.gz",
    "platform": "All",
    "description": "A backup utility for QEMU, KVM, XEN, and Virtualbox guests.\n\nVirt-back is a python application that uses the libvirt api to safely \nshutdown, gzip, and restart guests.  The backup process logs to syslog\nfor auditing and virt-back works great with cron for scheduling outages.\nVirt-back has been placed in the public domain and \nthe latest version may be downloaded here:\n\nhttps://git.unturf.com/python/virt-back\n\n\n**usage**\n\n```\nvirt-back --help\nusage: virt-back [-h] [-q] [-d] [-g] [-a amount] [-p 'PATH'] [-u 'URI'] [-i] [--info-all] [-b] [-r] [-s] [-c] [--backup-all] [--reboot-all] [--shutdown-all] [--create-all]\n\nA backup utility for QEMU, KVM, XEN, and Virtualbox guests. Virt-back is a python application that uses the libvirt api to safely shutdown, gzip, and restart guests. The backup process\nlogs to syslog for auditing and virt-back works great with cron for scheduling outages. Virt-back has been placed in the public domain and the latest version may be downloaded here:\n\nhttps://git.unturf.com/python/virt-back\n\noptions:\n  -h, --help            show this help message and exit\n  -q, --quiet           prevent output to stdout\n  -d, --date            append date to tar filename [default: no date]\n  -g, --no-gzip         do not gzip the resulting tar file\n  -a amount, --retention amount\n                        backups to retain [default: 3]\n  -p 'PATH', --path 'PATH'\n                        backup path [default: '/KVMBACK']\n  -u 'URI', --uri 'URI'\n                        optional hypervisor uri\n\nActions for info testing:\n  These options display info or test a list of guests.\n\n  -i, --info            info/test a list of guests (space delimited dom names)\n  --info-all            attempt to show info on ALL guests\n\nActions for a list of dom names:\n  WARNING: These options WILL bring down guests!\n\n  -b, --backup          backup a list of guests (space delimited dom names)\n  -r, --reboot          reboot a list of guests (space delimited dom names)\n  -s, --shutdown        shutdown a list of guests (space delimited dom names)\n  -c, --create          start a list of guests (space delimited dom names)\n\nActions for all doms:\n  WARNING: These options WILL bring down ALL guests!\n\n  --backup-all          attempt to shutdown, backup, and start ALL guests\n  --reboot-all          attempt to shutdown and then start ALL guests\n  --shutdown-all        attempt to shutdown ALL guests\n  --create-all          attempt to start ALL guests\n```\n\n\n## Dependencies\n\nBefore installing `virt-back`, you need to ensure that the necessary development libraries for `libvirt` are installed on your system. These libraries are required for the `libvirt-python` package, which `virt-back` depends on.\n\n### Fedora/RedHat\n\nOn Fedora or RedHat-based systems, you can install the `libvirt-devel` package using `dnf`:\n\n```bash\nsudo dnf install libvirt-devel\n```\n\n### Ubuntu/Debian\n\nOn Ubuntu or Debian-based systems, you can install the `libvirt-dev` package using `apt-get`:\n\n```bash\nsudo apt-get install libvirt-dev\n```\n\n### Installing `virt-back`\n\nOnce the necessary development libraries are installed, you can install `virt-back` using `pip`:\n\n```bash\npip install virt-back\n```\n\nThis will install `virt-back` along with its dependencies, including `libvirt-python`.\n\n\n## How to backup zfs snapshot all KVM instances on a TrueNAS Scale, \n\n```\nroot@guile[/mnt/downloads/virt-back]# ./virt-back -u \"qemu+unix:///system?socket=/run/truenas_libvirt/libvirt-sock\" --backup-all --path /mnt/personal/backup/virt-back --no-gzip --retention 5\n\nshutdown: invoking shutdown on 1_akuma\nshutdown: waited 0 seconds for 1_akuma to shut off\nbackup: invoking backup for 1_akuma\nbackup: checking if /dev/zvol/downloads/akuma-tfjpo7 is a ZFS dataset\nbackup: downloads/akuma-tfjpo7 is a ZFS dataset\nbackup: creating ZFS snapshot downloads/akuma-tfjpo7@backup-2024-07-07-2 for 1_akuma\nbackup: sending ZFS snapshot downloads/akuma-tfjpo7@backup-2024-07-07-2 to /mnt/personal/backup/virt-back/1_akuma-2024-07-07.zfs for 1_akuma\nbackup: skipping ISO file /mnt/downloads/iso/ubuntu-24.04-live-server-amd64.iso for 1_akuma\ncreate: invoking create on 1_akuma\nbackup: rotating backup files for 1_akuma\nbackup: archiving files for 1_akuma to /mnt/personal/backup/virt-back/1_akuma.tar\nbackup: archiving /mnt/personal/backup/virt-back/1_akuma.xml for 1_akuma\nbackup: checking if /dev/zvol/downloads/akuma-tfjpo7 is a ZFS dataset\nbackup: downloads/akuma-tfjpo7 is a ZFS dataset\nbackup: archiving /mnt/personal/backup/virt-back/1_akuma-2024-07-07.zfs for 1_akuma\nbackup: finished backup for 1_akuma\n```\n\n## Restoring from a ZFS Backup\n\nThis section explains how to restore a KVM instance from a ZFS backup using the `virt-back` utility. The process involves extracting the backup archive, restoring the ZFS snapshot, and creating a new VM in TrueNAS Scale using the restored ZFS volume.\n\n### Step-by-Step Restore Process\n\n1. **Extract the Backup Archive**: Extract the tar archive to get the ZFS snapshot file and the XML configuration file.\n2. **Restore the ZFS Snapshot to a New Dataset**: Use the `zfs receive` command to restore the ZFS snapshot to a new dataset.\n3. **Create a New VM in TrueNAS Scale**: Use the TrueNAS Scale UI to create a new VM and point it to the restored ZFS volume.\n\n### Detailed Steps\n\n#### 1. Extract the Backup Archive\n\nFirst, extract the tar archive to get the ZFS snapshot file and the XML configuration file. Use the `--strip-components` option to remove the leading directory components if necessary.\n\n```bash\ntar -xvf /mnt/personal/backup/virt-back/1_akuma.tar --strip-components=4 -C /mnt/personal/backup/virt-back\n```\n\nThis command will extract the files directly to the `/mnt/personal/backup/virt-back` directory, removing the leading directory components.\n\n#### 2. Restore the ZFS Snapshot to a New Dataset\n\nUse the `zfs receive` command to restore the ZFS snapshot to a new dataset. Assuming the extracted ZFS snapshot file is named `1_akuma-2024-07-07.zfs`:\n\n```bash\nzfs receive -F downloads/akuma-tfjpo7-restored < /mnt/personal/backup/virt-back/1_akuma-2024-07-07.zfs\n```\n\nThis command will restore the ZFS snapshot to the `downloads/akuma-tfjpo7-restored` dataset.\n\n#### 3. Create a New VM in TrueNAS Scale\n\n1. **Open TrueNAS Scale UI**: Log in to the TrueNAS Scale web interface.\n2. **Navigate to Virtual Machines**: Go to the \"Virtual Machines\" section.\n3. **Create a New VM**:\n   - Click on \"Add\" to create a new VM.\n   - Fill in the necessary details for the new VM (e.g., name, CPU, memory).\n4. **Attach the Restored ZFS Volume**:\n   - In the \"Disks\" section, add a new disk.\n   - Select \"Existing Zvol\" and choose the restored ZFS volume (`downloads/akuma-tfjpo7-restored`).\n5. **Complete the VM Creation**: Finish the VM creation process by following the remaining steps in the UI.\n\n### Summary\n\nBy following these steps, you can restore the ZFS snapshot and reattach it to a new VM using the TrueNAS Scale UI. This process involves extracting the backup archive, restoring the ZFS snapshot to a new dataset, and creating a new VM in TrueNAS Scale, pointing it to the restored ZFS volume. This approach ensures that the original dataset remains unaffected and allows you to easily restore and reattach your KVM instances. It's similar to cloning an existing instance except it's from a file backup so the machine will have all the attributes of the clone don't start them both at the same time because that would have IP address overlaps etc.\n",
    "bugtrack_url": null,
    "license": "Public Domain",
    "summary": "virt-back: A backup utility for QEMU, KVM, XEN, and Virtualbox guests",
    "version": "0.2.4",
    "project_urls": {
        "Homepage": "https://git.unturf.com/python/virt-back"
    },
    "split_keywords": [
        "backup",
        "virtual",
        "hypervisor",
        "qemu",
        "kvm",
        "xen",
        "virtualbox"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "130ac61c4fa525d8e4561c2e9e642edc858e04ba46a7a5d505ccd48ad152e44a",
                "md5": "64885e08e11a951a183882b708f27862",
                "sha256": "61dec01215214a56d91cdb9d2d3ed1d4a169cb77c7cb08f43efec8fa19a2bf6f"
            },
            "downloads": -1,
            "filename": "virt-back-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "64885e08e11a951a183882b708f27862",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14733,
            "upload_time": "2024-07-08T12:54:16",
            "upload_time_iso_8601": "2024-07-08T12:54:16.516259Z",
            "url": "https://files.pythonhosted.org/packages/13/0a/c61c4fa525d8e4561c2e9e642edc858e04ba46a7a5d505ccd48ad152e44a/virt-back-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-08 12:54:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "virt-back"
}
        
Elapsed time: 5.03859s