Skip to content

Commit

Permalink
version 1.9.23
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbi committed Apr 16, 2023
1 parent d61b0ee commit 0f023d1
Show file tree
Hide file tree
Showing 23 changed files with 157 additions and 95 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci-ubuntu-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: abbbi/github-actions-tune@v1
- name: codespell
run: |
sudo apt-get update
sudo apt-get install codespell -y
codespell libvirtnbdbackup
codespell virtnbdbackup
codespell virtnbdrestore
codespell virtnbdmap
codespell virtnbd-nbdkit-plugin
codespell README.md
- name: Python code format test
run: |
sudo pip3 install black==22.3
Expand Down
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 1.9.23
---------
* Code cleanups
* Spelling fixes, run codespell during CI

Version 1.9.22
---------
* Code cleanups, pylint warning
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ with qcow(v3) based disk images. If you are using older image versions, you can
only create `copy` backups, or consider converting the images to a newer
format using `qemu-img`.

By default `virtnbdbackup` will exclude all disks with format `raw` aswell
By default `virtnbdbackup` will exclude all disks with format `raw` as well
as direct attached (passthrough) disks such as LVM or ZVOL and ISCSI
volumes. These type of disks do not support storing checkpoint/bitmap
metadata.
Expand All @@ -291,7 +291,7 @@ During restore, these files can be copied "as is" from the backup folder and
must not be processed using `virtnbdrestore`.

`Note:`
> The backup data for raw disks will only be crash consistant, be aware
> The backup data for raw disks will only be crash consistent, be aware
> that this might result in inconsistent filesystems after restoring!

Expand Down Expand Up @@ -412,7 +412,7 @@ virtnbdbackup -d vm1 -l inc -o /tmp/backupset -p

`Note:`
> Not all libvirt versions support the flag required to read the checkpoint
> size. If the estimated checkpoint size is allways 0, your libvirt version
> size. If the estimated checkpoint size is always 0, your libvirt version
> might miss the required features.
## Backup threshold
Expand Down Expand Up @@ -440,7 +440,7 @@ has attached, it might make sense to try a different amount of workers to see
which amount your hardware can handle best.

If standard output (`-`) is defined as backup target, the amount of workers is
allways limited to 1, to ensure a valid Zip file format.
always limited to 1, to ensure a valid Zip file format.

## Compression

Expand All @@ -460,7 +460,7 @@ block and original data are enabled.

## Remote Backup

It is also possible to backup remote libvirt systems. The most convinient way
It is also possible to backup remote libvirt systems. The most convenient way
is to use ssh for initiating the libvirt connection (key authentication
mandatory).

Expand Down Expand Up @@ -558,7 +558,7 @@ During restore unzip the data from both zip files into a single directory:

If an domain has configured custom kernel, initrd, loader or nvram images
(usually the case if the domain boots from OVM UEFI BIOS), these files will be
saved to the backup folder aswell.
saved to the backup folder as well.

# Restore examples

Expand Down Expand Up @@ -607,8 +607,8 @@ in the output directory `/tmp/restore`

`Note`:
> The restore utility will copy the latest virtual machine config to the
> target directory, but wont alter its contents. You have to adjust the config
> file for the new pathes and/or excluded disks to be able to define and run it.
> target directory, but won't alter its contents. You have to adjust the config
> file for the new paths and/or excluded disks to be able to define and run it.
## Process only specific disks during restore

Expand Down Expand Up @@ -646,11 +646,11 @@ restore accordingly, the following changes are done:
* UUID of the virtual machine is removed from the config file
* Name of the virtual machine is prefixed with "restore_" (use option
`--name` to specify desired vm name)
* The disk pathes to the virtual machine are changed to the new target directory.
* The disk paths to the virtual machine are changed to the new target directory.
* If virtual machine was operating on snapshots/backing store images, the
references to the configured backing stores will be removed.
* Raw devices are removed from VM config if `--raw` is not specified, aswell
as floppy or cdrom devices (which arent part of the backup).
* Raw devices are removed from VM config if `--raw` is not specified, as well
as floppy or cdrom devices (which aren't part of the backup).

`Note:`
> If missing, Kernel, UEFI or NVRAM files are restored to their original
Expand Down Expand Up @@ -863,13 +863,13 @@ See [past issues](https://github.com/abbbi/virtnbdbackup/issues?q=label%3Aopenne
Both `virtnbdbackup` and `virtnbdrestore` commands support authenticating
against libvirtd with the usual URIs. Consider using the following options:

`-U`: Specify an arbitary connection URI to use against libvirt
`-U`: Specify an arbitrary connection URI to use against libvirt

`--user`: Username to use for the specified connection URI

`--password`: Password to use for the specified connection URI.

It is also possible to specifiy the credentials stored as authentication file
It is also possible to specify the credentials stored as authentication file
like it would be possible using the `virsh -c` option:

```
Expand Down
2 changes: 1 addition & 1 deletion libvirtnbdbackup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

__version__ = "1.9.22"
__version__ = "1.9.23"
4 changes: 2 additions & 2 deletions libvirtnbdbackup/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def getLatest(targetDir: str, search: str, key=None) -> List[str]:
def hasQcowDisks(diskList: List[Any]) -> bool:
"""Check if the list of attached disks includes at least one
qcow image based disk, else checkpoint handling can be
skipped and backup modue falls back to type copy"""
skipped and backup module falls back to type copy"""
for disk in diskList:
if disk.format.startswith("qcow"):
return True
Expand Down Expand Up @@ -202,7 +202,7 @@ def killProc(pid: int) -> bool:


def getIdent(args: Namespace) -> Union[str, int]:
"""Used to get an uniqe identifier for target files,
"""Used to get an unique identifier for target files,
usually checkpoint name is used, but if no checkpoint
is created, we use timestamp"""
try:
Expand Down
8 changes: 4 additions & 4 deletions libvirtnbdbackup/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ class CheckpointException(Exception):


class NoCheckpointsFound(CheckpointException):
"""Inc or differencial backup attempted but
"""Inc or differential backup attempted but
no existing checkpoints are found."""


class RedefineCheckpointError(CheckpointException):
"""During redefining existing checkpoints after
vm relocate, an error occured"""
vm relocate, an error occurred"""


class ReadCheckpointsError(CheckpointException):
"""Cant read checkpoint file"""
"""Can't read checkpoint file"""


class RemoveCheckpointError(CheckpointException):
"""During removal of existing checkpoints after
an error occured"""
an error occurred"""


class SaveCheckpointError(CheckpointException):
Expand Down
2 changes: 1 addition & 1 deletion libvirtnbdbackup/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def backupBootConfig(args: Namespace) -> None:


def backupAutoStart(args: Namespace) -> None:
"""Save information wether if virtual machine was marked
"""Save information if virtual machine was marked
for autostart during system boot"""
log.info("Autostart setting configured for virtual machine.")
autoStartFile = f"{args.output}/autostart.{lib.getIdent(args)}"
Expand Down
1 change: 1 addition & 0 deletions libvirtnbdbackup/nbdcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
__version__ = "0.1"

from .client import client, Unix, TCP
from . import context
38 changes: 38 additions & 0 deletions libvirtnbdbackup/nbdcli/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Copyright (C) 2023 Michael Ablassmeier <abi@grinser.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import logging
from argparse import Namespace
from libvirtnbdbackup.virt.client import DomainDisk

log = logging.getLogger("nbdctx")


def get(args: Namespace, disk: DomainDisk) -> str:
"""Get required meta context string passed to nbd server based on
backup type"""
metaContext = ""
if args.level not in ("inc", "diff"):
return metaContext

if args.offline is True:
metaContext = f"qemu:dirty-bitmap:{args.cpt.name}"
else:
metaContext = f"qemu:dirty-bitmap:backup-{disk.target}"

logging.info("Using NBD meta context [%s]", metaContext)

return metaContext
2 changes: 1 addition & 1 deletion libvirtnbdbackup/output/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class OutputOpenException(OutputException):


class OutputCreateDirectory(OutputException):
"""Cant create output directory"""
"""Can't create output directory"""
35 changes: 35 additions & 0 deletions libvirtnbdbackup/output/stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Copyright (C) 2023 Michael Ablassmeier <abi@grinser.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from argparse import Namespace
from typing import Union
from libvirtnbdbackup import output


def get(
args: Namespace, repository: output.target
) -> Union[output.target.Directory, output.target.Zip]:
"""Get filehandle for output files based on output
mode"""
fileStream: Union[output.target.Directory, output.target.Zip]
if args.stdout is False:
fileStream = repository.Directory(args.output)
else:
fileStream = repository.Zip()
args.output = "./"
args.worker = 1

return fileStream
22 changes: 18 additions & 4 deletions libvirtnbdbackup/output/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, targetDir: str) -> None:
self._makeDir()

def _makeDir(self) -> None:
"""Create output directoy on init"""
"""Create output directory on init"""
if os.path.exists(self.targetDir):
if not os.path.isdir(self.targetDir):
raise exceptions.OutputCreateDirectory(
Expand Down Expand Up @@ -83,6 +83,16 @@ def flush(self):
"""Flush wrapper"""
return self.fileHandle.flush()

def truncate(self, size: int) -> None:
"""Truncate target file"""
try:
self.fileHandle.truncate(size)
self.fileHandle.seek(0)
except OSError as e:
raise exceptions.OutputException(
f"Failed to truncate target file: [{e}]"
) from e

def close(self):
"""Close wrapper"""
return self.fileHandle.close()
Expand Down Expand Up @@ -135,10 +145,14 @@ def open(self, fileName: str, mode: Literal["w"] = "w") -> IO[bytes]:

return False

def close(self):
"""Close wrapper"""
return self.zipFileStream.close()
def truncate(self, size: int) -> None:
"""Truncate target file"""
raise RuntimeError("Not implemented")

def write(self, data):
"""Write wrapper"""
return self.zipFileStream.write(data)

def close(self):
"""Close wrapper"""
return self.zipFileStream.close()
2 changes: 1 addition & 1 deletion libvirtnbdbackup/sparsestream/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def dumpMetadata(
disk,
):
"""First block in backup stream is Meta data information
about virtual size of the disk being backed up, aswell
about virtual size of the disk being backed up, as well
as various information regarding backup.
Dumps Metadata frame to be written at start of stream in
json format.
Expand Down
2 changes: 1 addition & 1 deletion libvirtnbdbackup/ssh/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def connect(self) -> SSHClient:
)
except Exception as e:
log.exception(e)
raise exceptions.sshError(f"Unknown exception occured: {e}")
raise exceptions.sshError(f"Unknown exception occurred: {e}")

@property
def sftp(self) -> SFTPClient:
Expand Down
6 changes: 3 additions & 3 deletions libvirtnbdbackup/virt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _isSsh(uri: str) -> bool:
return uri.startswith("qemu+ssh")

def _useAuth(self, args: Namespace) -> bool:
"""Check wether we want to use advanced auth method"""
"""Check if we want to use advanced auth method"""
if args.uri.startswith("qemu+"):
return True
if self._reqAuth(args.uri):
Expand Down Expand Up @@ -285,7 +285,7 @@ def adjustDomainConfig(
self, args: Namespace, restoreDisk: DomainDisk, vmConfig: str, targetFile: str
) -> bytes:
"""Adjust virtual machine configuration after restoring. Changes
the pathes to the virtual machine disks and attempts to remove
the paths to the virtual machine disks and attempts to remove
components excluded during restore."""
tree = xml.asTree(vmConfig)

Expand Down Expand Up @@ -329,7 +329,7 @@ def adjustDomainConfig(
continue
backingStore = disk.xpath("backingStore")
if backingStore:
log.info("Removing existant backing store settings")
log.info("Removing existent backing store settings")
disk.remove(backingStore[0])

originalFile = disk.xpath("source")[0].get("file")
Expand Down
6 changes: 3 additions & 3 deletions libvirtnbdbackup/virt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class virtHelperError(Exception):


class domainNotFound(virtHelperError):
"""Cant find domain"""
"""Can't find domain"""


class connectionFailed(virtHelperError):
"""Cant connect libvirtd domain"""
"""Can't connect libvirtd domain"""


class startBackupFailed(virtHelperError):
"""Cant start backup operation"""
"""Can't start backup operation"""
2 changes: 1 addition & 1 deletion libvirtnbdbackup/virt/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def indent(top: _Element) -> str:
except ElementTree.ParseError as errmsg:
log.debug("Failed to parse xml: [%s]", errmsg)
except AttributeError:
# older ElementTree verisons dont have the
# older ElementTree versions dont have the
# indent method, skip silently and use
# non formatted string
pass
Expand Down
4 changes: 2 additions & 2 deletions man/virtnbdbackup.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.1.
.TH VIRTNBDBACKUP "1" "March 2023" "virtnbdbackup 1.9.22" "User Commands"
.TH VIRTNBDBACKUP "1" "April 2023" "virtnbdbackup 1.9.23" "User Commands"
.SH NAME
virtnbdbackup \- backup utility for libvirt
.SH DESCRIPTION
Expand Down Expand Up @@ -48,7 +48,7 @@ Backup only disk with target dev name (\fB\-i\fR vda)
Exclude disk(s) with target dev name (\fB\-x\fR vda,vdb)
.TP
\fB\-f\fR SOCKETFILE, \fB\-\-socketfile\fR SOCKETFILE
Use specified file for NBD Server socket (default: \fI\,/var/tmp/virtnbdbackup.65893\/\fP)
Use specified file for NBD Server socket (default: \fI\,/var/tmp/virtnbdbackup.35855\/\fP)
.TP
\fB\-n\fR, \fB\-\-noprogress\fR
Disable progress bar
Expand Down
Loading

0 comments on commit 0f023d1

Please sign in to comment.