From d61b0eedea7438581f0e0c50c074a1a1d2536bc8 Mon Sep 17 00:00:00 2001 From: Michael Ablassmeier Date: Sun, 2 Apr 2023 18:21:33 +0200 Subject: [PATCH] version 1.9.22 --- Changelog | 7 ++- README.md | 6 +-- libvirtnbdbackup/__init__.py | 4 +- libvirtnbdbackup/argopt.py | 2 +- libvirtnbdbackup/chunk.py | 2 +- libvirtnbdbackup/{common => }/common.py | 8 +-- libvirtnbdbackup/common/__init__.py | 19 ------- libvirtnbdbackup/extenthandler/__init__.py | 2 +- .../extenthandler/extenthandler.py | 2 +- libvirtnbdbackup/logcount.py | 2 +- libvirtnbdbackup/metadata.py | 2 +- libvirtnbdbackup/nbdcli/__init__.py | 2 +- libvirtnbdbackup/nbdcli/client.py | 2 +- libvirtnbdbackup/output/target.py | 2 +- libvirtnbdbackup/partialfile.py | 54 +++++++++++++++++++ libvirtnbdbackup/{common => }/processinfo.py | 2 +- libvirtnbdbackup/qemu/__init__.py | 2 +- libvirtnbdbackup/qemu/command.py | 2 +- libvirtnbdbackup/qemu/util.py | 4 +- libvirtnbdbackup/sighandle.py | 52 +++++++++++++----- libvirtnbdbackup/sparsestream/__init__.py | 2 +- libvirtnbdbackup/sparsestream/streamer.py | 2 +- libvirtnbdbackup/sparsestream/types.py | 2 +- libvirtnbdbackup/ssh/__init__.py | 2 +- libvirtnbdbackup/ssh/client.py | 4 +- libvirtnbdbackup/virt/__init__.py | 2 +- libvirtnbdbackup/virt/checkpoint.py | 2 +- libvirtnbdbackup/virt/client.py | 2 +- man/virtnbdbackup.1 | 4 +- man/virtnbdmap.1 | 2 +- man/virtnbdrestore.1 | 4 +- virtnbd-nbdkit-plugin | 2 +- virtnbdbackup | 40 +++----------- virtnbdmap | 26 +++------ virtnbdrestore | 19 ++----- 35 files changed, 152 insertions(+), 141 deletions(-) rename libvirtnbdbackup/{common => }/common.py (96%) delete mode 100644 libvirtnbdbackup/common/__init__.py create mode 100644 libvirtnbdbackup/partialfile.py rename libvirtnbdbackup/{common => }/processinfo.py (93%) diff --git a/Changelog b/Changelog index d688c5b8..26e09fd6 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,8 @@ +Version 1.9.22 +--------- + * Code cleanups, pylint warning + * Update copyright stanca + Version 1.9.21 --------- * Code cleanups @@ -10,7 +15,7 @@ Version 1.9.20 Version 1.9.19 --------- - * Code cleanup: move some functions to seperate files. + * Code cleanup: move some functions to separate files. Version 1.9.18 --------- diff --git a/README.md b/README.md index 00ee6c38..14208feb 100644 --- a/README.md +++ b/README.md @@ -338,7 +338,7 @@ machine, including logfiles that can be used for analyzing backup issues: During backup `virtnbdbackup` attempts to freeze all file systems within the domain using the qemu guest agent filesystem freeze and thaw functions. In -case no qemu agent is installed or filesystem freeze fails, a warning is issued +case no qemu agent is installed or filesystem freeze fails, a warning is shown during backup: ``` @@ -968,8 +968,8 @@ See also: https://github.com/abbbi/virtnbdbackup/issues/8 The utility is provided "as is", i take no responsibility or warranty if you face any issues recovering your data! The only way to ensure your backups are valid and your backup plan works correctly is to repeatedly test the integrity -by restoring them! If you discover any issues, please do not hesitate to open -an issue. +by restoring them! If you discover any issues, please do not hesitate to report +them. ## Links diff --git a/libvirtnbdbackup/__init__.py b/libvirtnbdbackup/__init__.py index ff56f589..826ef3bc 100644 --- a/libvirtnbdbackup/__init__.py +++ b/libvirtnbdbackup/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 @@ -15,4 +15,4 @@ along with this program. If not, see . """ -__version__ = "1.9.21" +__version__ = "1.9.22" diff --git a/libvirtnbdbackup/argopt.py b/libvirtnbdbackup/argopt.py index dc698522..d63cd8e9 100644 --- a/libvirtnbdbackup/argopt.py +++ b/libvirtnbdbackup/argopt.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 """ - Copyright (C) 2022 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/chunk.py b/libvirtnbdbackup/chunk.py index 3e8470f3..35a4abee 100644 --- a/libvirtnbdbackup/chunk.py +++ b/libvirtnbdbackup/chunk.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/common/common.py b/libvirtnbdbackup/common.py similarity index 96% rename from libvirtnbdbackup/common/common.py rename to libvirtnbdbackup/common.py index 88b26e0c..a1bfccb7 100644 --- a/libvirtnbdbackup/common/common.py +++ b/libvirtnbdbackup/common.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 @@ -107,12 +107,6 @@ def configLogger( ) -def partialBackup(args: Namespace) -> int: - """Check for possible partial backup files""" - partialFiles = glob.glob(f"{args.output}/*.partial") - return len(partialFiles) > 0 - - def hasFullBackup(args: Namespace) -> int: """Check if full backup file exists in target directory""" fullFiles = glob.glob(f"{args.output}/*.full.data") diff --git a/libvirtnbdbackup/common/__init__.py b/libvirtnbdbackup/common/__init__.py deleted file mode 100644 index 7c1ff4d3..00000000 --- a/libvirtnbdbackup/common/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -""" - Copyright (C) 2021 Michael Ablassmeier - - 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 . -""" - -__title__ = "common" -__version__ = "0.1" diff --git a/libvirtnbdbackup/extenthandler/__init__.py b/libvirtnbdbackup/extenthandler/__init__.py index b904e149..565fa310 100644 --- a/libvirtnbdbackup/extenthandler/__init__.py +++ b/libvirtnbdbackup/extenthandler/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/extenthandler/extenthandler.py b/libvirtnbdbackup/extenthandler/extenthandler.py index 92ff1f45..611990c4 100644 --- a/libvirtnbdbackup/extenthandler/extenthandler.py +++ b/libvirtnbdbackup/extenthandler/extenthandler.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/logcount.py b/libvirtnbdbackup/logcount.py index 5a16022d..9b33a702 100644 --- a/libvirtnbdbackup/logcount.py +++ b/libvirtnbdbackup/logcount.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/metadata.py b/libvirtnbdbackup/metadata.py index ec2237c1..737dc853 100644 --- a/libvirtnbdbackup/metadata.py +++ b/libvirtnbdbackup/metadata.py @@ -22,7 +22,7 @@ from libvirtnbdbackup import output from libvirtnbdbackup.virt.client import DomainDisk -from libvirtnbdbackup.common import common as lib +from libvirtnbdbackup import common as lib from libvirtnbdbackup.qemu import util as qemu from libvirtnbdbackup.qemu.exceptions import ProcessError from libvirtnbdbackup.ssh.exceptions import sshError diff --git a/libvirtnbdbackup/nbdcli/__init__.py b/libvirtnbdbackup/nbdcli/__init__.py index 191b74da..254a97cc 100644 --- a/libvirtnbdbackup/nbdcli/__init__.py +++ b/libvirtnbdbackup/nbdcli/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/nbdcli/client.py b/libvirtnbdbackup/nbdcli/client.py index 16f7fa08..72d0c04a 100644 --- a/libvirtnbdbackup/nbdcli/client.py +++ b/libvirtnbdbackup/nbdcli/client.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/output/target.py b/libvirtnbdbackup/output/target.py index feed1108..9ce5fe88 100644 --- a/libvirtnbdbackup/output/target.py +++ b/libvirtnbdbackup/output/target.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/partialfile.py b/libvirtnbdbackup/partialfile.py new file mode 100644 index 00000000..e2d8997d --- /dev/null +++ b/libvirtnbdbackup/partialfile.py @@ -0,0 +1,54 @@ +""" + Copyright (C) 2023 Michael Ablassmeier + + 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 . +""" + +import os +import glob +import logging +from argparse import Namespace + +from libvirtnbdbackup import exceptions + + +log = logging.getLogger() + + +def _exists(args: Namespace) -> int: + """Check for possible partial backup files""" + partialFiles = glob.glob(f"{args.output}/*.partial") + return len(partialFiles) > 0 + + +def exists(args: Namespace) -> bool: + """Check if target directory has an partial backup, + makes backup utility exit errnous in case backup + type is full or inc""" + if args.level in ("inc", "diff") and args.stdout is False and _exists(args) is True: + log.error("Partial backup found in target directory: [%s]", args.output) + log.error("One of the last backups seems to have failed.") + log.error("Consider re-executing full backup.") + return True + + return False + + +def rename(targetFilePartial: str, targetFile: str) -> None: + """After backup, move .partial file to real + target file""" + try: + os.rename(targetFilePartial, targetFile) + except OSError as e: + raise exceptions.DiskBackupFailed(f"Failed to rename file: [{e}]") from e diff --git a/libvirtnbdbackup/common/processinfo.py b/libvirtnbdbackup/processinfo.py similarity index 93% rename from libvirtnbdbackup/common/processinfo.py rename to libvirtnbdbackup/processinfo.py index 289920f7..cd57e04b 100644 --- a/libvirtnbdbackup/common/processinfo.py +++ b/libvirtnbdbackup/processinfo.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2022 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/qemu/__init__.py b/libvirtnbdbackup/qemu/__init__.py index 05d96a8b..83cab960 100644 --- a/libvirtnbdbackup/qemu/__init__.py +++ b/libvirtnbdbackup/qemu/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/qemu/command.py b/libvirtnbdbackup/qemu/command.py index 2060180a..4ccbcdc4 100644 --- a/libvirtnbdbackup/qemu/command.py +++ b/libvirtnbdbackup/qemu/command.py @@ -24,7 +24,7 @@ ProcessError, ) from libvirtnbdbackup.output import openfile -from libvirtnbdbackup.common.processinfo import processInfo +from libvirtnbdbackup.processinfo import processInfo log = logging.getLogger(__name__) diff --git a/libvirtnbdbackup/qemu/util.py b/libvirtnbdbackup/qemu/util.py index 927a1b9c..943bb62b 100644 --- a/libvirtnbdbackup/qemu/util.py +++ b/libvirtnbdbackup/qemu/util.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 @@ -23,7 +23,7 @@ from argparse import Namespace from libvirtnbdbackup.ssh.exceptions import sshError -from libvirtnbdbackup.common.processinfo import processInfo +from libvirtnbdbackup.processinfo import processInfo from libvirtnbdbackup.qemu import command from libvirtnbdbackup.virt.client import DomainDisk diff --git a/libvirtnbdbackup/sighandle.py b/libvirtnbdbackup/sighandle.py index 1fbc21e0..12d8302a 100644 --- a/libvirtnbdbackup/sighandle.py +++ b/libvirtnbdbackup/sighandle.py @@ -15,24 +15,48 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ +import os import sys from argparse import Namespace from typing import Any from libvirt import virDomain from libvirtnbdbackup import virt +from libvirtnbdbackup import common as lib +from libvirtnbdbackup.processinfo import processInfo +from libvirtnbdbackup.qemu import util as qemu -def catch( - args: Namespace, - domObj: virDomain, - virtClient: virt.client, - log: Any, - signum: int, - _, -) -> None: - """Catch signal, attempt to stop running backup job.""" - log.error("Caught signal: %s", signum) - log.error("Cleanup: Stopping backup job") - if args.offline is not True: - virtClient.stopBackup(domObj) - sys.exit(1) +class Backup: + """Handle signal during backup operation""" + + @staticmethod + def catch( + args: Namespace, + domObj: virDomain, + virtClient: virt.client, + log: Any, + signum: int, + _, + ) -> None: + """Catch signal, attempt to stop running backup job.""" + log.error("Caught signal: %s", signum) + log.error("Cleanup: Stopping backup job") + if args.offline is not True: + virtClient.stopBackup(domObj) + sys.exit(1) + + +class Map: + """Handle signal during map operation""" + + @staticmethod + def catch(nbdkitProcess: processInfo, device: str, blockMap, log, signum, _): + """Catch signal, attempt to stop processes.""" + log.info("Received signal: [%s]", signum) + qemu.util("").disconnect(device) + log.info("Removing temporary blockmap file: [%s]", blockMap.name) + os.remove(blockMap.name) + log.info("Removing nbdkit logfile: [%s]", nbdkitProcess.logFile) + os.remove(nbdkitProcess.logFile) + lib.killProc(nbdkitProcess.pid) + sys.exit(0) diff --git a/libvirtnbdbackup/sparsestream/__init__.py b/libvirtnbdbackup/sparsestream/__init__.py index 77e15004..815a070b 100644 --- a/libvirtnbdbackup/sparsestream/__init__.py +++ b/libvirtnbdbackup/sparsestream/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/sparsestream/streamer.py b/libvirtnbdbackup/sparsestream/streamer.py index 9dd5eb4b..726be100 100644 --- a/libvirtnbdbackup/sparsestream/streamer.py +++ b/libvirtnbdbackup/sparsestream/streamer.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier Copyright (C) 2020 Red Hat, Inc. This program is free software: you can redistribute it and/or modify diff --git a/libvirtnbdbackup/sparsestream/types.py b/libvirtnbdbackup/sparsestream/types.py index 816f86e4..149ec942 100644 --- a/libvirtnbdbackup/sparsestream/types.py +++ b/libvirtnbdbackup/sparsestream/types.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier Copyright (C) 2020 Red Hat, Inc. This program is free software: you can redistribute it and/or modify diff --git a/libvirtnbdbackup/ssh/__init__.py b/libvirtnbdbackup/ssh/__init__.py index f0c24d85..ae32f842 100644 --- a/libvirtnbdbackup/ssh/__init__.py +++ b/libvirtnbdbackup/ssh/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/ssh/client.py b/libvirtnbdbackup/ssh/client.py index 54b16530..d5ed037c 100644 --- a/libvirtnbdbackup/ssh/client.py +++ b/libvirtnbdbackup/ssh/client.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2022 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 @@ -26,7 +26,7 @@ ) from libvirtnbdbackup.ssh import exceptions -from libvirtnbdbackup.common.processinfo import processInfo +from libvirtnbdbackup.processinfo import processInfo log = logging.getLogger("ssh") diff --git a/libvirtnbdbackup/virt/__init__.py b/libvirtnbdbackup/virt/__init__.py index 52277b8e..b7c5b3b1 100644 --- a/libvirtnbdbackup/virt/__init__.py +++ b/libvirtnbdbackup/virt/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/libvirtnbdbackup/virt/checkpoint.py b/libvirtnbdbackup/virt/checkpoint.py index 52d0d222..63789593 100644 --- a/libvirtnbdbackup/virt/checkpoint.py +++ b/libvirtnbdbackup/virt/checkpoint.py @@ -25,7 +25,7 @@ from libvirtnbdbackup import output from libvirtnbdbackup.virt import xml from libvirtnbdbackup.output.exceptions import OutputException -from libvirtnbdbackup.common.common import defaultCheckpointName +from libvirtnbdbackup.common import defaultCheckpointName from libvirtnbdbackup.exceptions import ( NoCheckpointsFound, ReadCheckpointsError, diff --git a/libvirtnbdbackup/virt/client.py b/libvirtnbdbackup/virt/client.py index 43dede1f..4d36a8d0 100644 --- a/libvirtnbdbackup/virt/client.py +++ b/libvirtnbdbackup/virt/client.py @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/man/virtnbdbackup.1 b/man/virtnbdbackup.1 index cd42dd7c..e9cc4588 100644 --- a/man/virtnbdbackup.1 +++ b/man/virtnbdbackup.1 @@ -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.21" "User Commands" +.TH VIRTNBDBACKUP "1" "March 2023" "virtnbdbackup 1.9.22" "User Commands" .SH NAME virtnbdbackup \- backup utility for libvirt .SH DESCRIPTION @@ -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.3131\/\fP) +Use specified file for NBD Server socket (default: \fI\,/var/tmp/virtnbdbackup.65893\/\fP) .TP \fB\-n\fR, \fB\-\-noprogress\fR Disable progress bar diff --git a/man/virtnbdmap.1 b/man/virtnbdmap.1 index 1af4ddc1..3247438e 100644 --- a/man/virtnbdmap.1 +++ b/man/virtnbdmap.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.1. -.TH VIRTNBDMAP "1" "March 2023" "virtnbdmap 1.9.21" "User Commands" +.TH VIRTNBDMAP "1" "March 2023" "virtnbdmap 1.9.22" "User Commands" .SH NAME virtnbdmap \- map virtnbdbackup image files to nbd devices .SH DESCRIPTION diff --git a/man/virtnbdrestore.1 b/man/virtnbdrestore.1 index 128d6cf9..1e2b745b 100644 --- a/man/virtnbdrestore.1 +++ b/man/virtnbdrestore.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.1. -.TH VIRTNBDRESTORE "1" "March 2023" "virtnbdrestore 1.9.21" "User Commands" +.TH VIRTNBDRESTORE "1" "March 2023" "virtnbdrestore 1.9.22" "User Commands" .SH NAME virtnbdrestore \- restore utility for libvirt .SH DESCRIPTION @@ -40,7 +40,7 @@ Process only disk matching target dev name. (default: None) Disable progress bar .TP \fB\-f\fR SOCKETFILE, \fB\-\-socketfile\fR SOCKETFILE -Use specified file for NBD Server socket (default: \fI\,/var/tmp/virtnbdbackup.3136\/\fP) +Use specified file for NBD Server socket (default: \fI\,/var/tmp/virtnbdbackup.65899\/\fP) .TP \fB\-r\fR, \fB\-\-raw\fR Copy raw images as is during restore. (default: False) diff --git a/virtnbd-nbdkit-plugin b/virtnbd-nbdkit-plugin index 6968e863..0fc34a0a 100644 --- a/virtnbd-nbdkit-plugin +++ b/virtnbd-nbdkit-plugin @@ -1,5 +1,5 @@ """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 diff --git a/virtnbdbackup b/virtnbdbackup index 0aa4460f..2f5d28a3 100755 --- a/virtnbdbackup +++ b/virtnbdbackup @@ -1,6 +1,6 @@ #!/usr/bin/python3 """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 @@ -37,8 +37,8 @@ from libvirtnbdbackup import virt from libvirtnbdbackup.virt.client import DomainDisk from libvirtnbdbackup.virt import checkpoint from libvirtnbdbackup import output -from libvirtnbdbackup.common import common as lib -from libvirtnbdbackup.common.processinfo import processInfo +from libvirtnbdbackup import common as lib +from libvirtnbdbackup.processinfo import processInfo from libvirtnbdbackup.logcount import logCount from libvirtnbdbackup.sparsestream import streamer from libvirtnbdbackup.sparsestream import types @@ -46,6 +46,7 @@ from libvirtnbdbackup import metadata from libvirtnbdbackup import exceptions from libvirtnbdbackup import chunk from libvirtnbdbackup import block +from libvirtnbdbackup import partialfile from libvirtnbdbackup.ssh.exceptions import sshError from libvirtnbdbackup.nbdcli.exceptions import NbdClientException from libvirtnbdbackup.qemu.exceptions import ProcessError @@ -69,23 +70,6 @@ def setOfflineArguments(args: Namespace, domObj: virDomain) -> None: args.offline = True -def hasPartial(args: Namespace) -> bool: - """Check if target directory has an partial backup, - makes backup utility exit errnous in case backup - type is full or inc""" - if ( - args.level in ("inc", "diff") - and args.stdout is False - and lib.partialBackup(args) is True - ): - logging.error("Partial backup found in target directory: [%s]", args.output) - logging.error("One of the last backups seems to have failed.") - logging.error("Consider re-executing full backup.") - return True - - return False - - def getFileStream( args: Namespace, repository: output.target ) -> Union[output.target.Directory, output.target.Zip]: @@ -377,7 +361,7 @@ def main() -> None: ) sys.exit(1) - if hasPartial(args): + if partialfile.exists(args): sys.exit(1) if not args.checkpointdir: @@ -415,7 +399,8 @@ def main() -> None: sys.exit(1) signal.signal( - signal.SIGINT, partial(sighandle.catch, args, domObj, virtClient, logging) + signal.SIGINT, + partial(sighandle.Backup.catch, args, domObj, virtClient, logging), ) vmConfig = virtClient.getDomainConfig(domObj) @@ -630,15 +615,6 @@ def getExtentHandler(args: Namespace, nbdClient): return extentHandler -def renamePartial(targetFilePartial: str, targetFile: str) -> None: - """After backup, move .partial file to real - target file""" - try: - os.rename(targetFilePartial, targetFile) - except OSError as e: - raise exceptions.DiskBackupFailed(f"Failed to rename file: [{e}]") from e - - def startOfflineNBD( args: Namespace, disk: DomainDisk, remoteHost: str, port: int ) -> processInfo: @@ -850,7 +826,7 @@ def backupDisk( logging.info( "Backup of disk [%s] finished, file: [%s]", disk.target, targetFile ) - renamePartial(targetFilePartial, targetFile) + partialfile.rename(targetFilePartial, targetFile) return True diff --git a/virtnbdmap b/virtnbdmap index a7c4e86f..2d7f4dbe 100755 --- a/virtnbdmap +++ b/virtnbdmap @@ -1,6 +1,6 @@ #!/usr/bin/python3 """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 @@ -20,23 +20,21 @@ import sys import shutil import tempfile import signal -from functools import partial import json import time import argparse -from argparse import Namespace import logging - +from functools import partial +from argparse import Namespace from typing import List, Tuple, Dict, IO from libvirtnbdbackup import argopt from libvirtnbdbackup import __version__ +from libvirtnbdbackup import sighandle from libvirtnbdbackup.qemu import util as qemu -from libvirtnbdbackup.qemu import command from libvirtnbdbackup.qemu.exceptions import ProcessError, QemuHelperError from libvirtnbdbackup import output from libvirtnbdbackup.output.exceptions import OutputException -from libvirtnbdbackup.common import common as lib -from libvirtnbdbackup.common.processinfo import processInfo +from libvirtnbdbackup import common as lib from libvirtnbdbackup.logcount import logCount from libvirtnbdbackup.exceptions import RestoreError from libvirtnbdbackup.sparsestream import streamer @@ -105,18 +103,6 @@ def replayChanges(dataRanges: List, args: Namespace) -> None: progressBar.close() -def handleSignal(nbdkitProcess: processInfo, device: str, blockMap, log, signum, _): - """Catch signal, attempt to stop processes.""" - log.info("Received signal: [%s]", signum) - qemu.util("").disconnect(device) - log.info("Removing temporary blockmap file: [%s]", blockMap.name) - os.remove(blockMap.name) - log.info("Removing nbdkit logfile: [%s]", nbdkitProcess.logFile) - os.remove(nbdkitProcess.logFile) - lib.killProc(nbdkitProcess.pid) - sys.exit(0) - - def getDataRanges(stream, sTypes, reader) -> Tuple[List, Dict]: """Read block offsets from backup stream image""" try: @@ -327,7 +313,7 @@ def main() -> None: ) signal.signal( signal.SIGINT, - partial(handleSignal, nbdkitProcess, args.device, blockMap, logging), + partial(sighandle.Map.catch, nbdkitProcess, args.device, blockMap, logging), ) maxRetry = 10 diff --git a/virtnbdrestore b/virtnbdrestore index 67390a74..553d0f64 100755 --- a/virtnbdrestore +++ b/virtnbdrestore @@ -1,6 +1,6 @@ #!/usr/bin/python3 """ - Copyright (C) 2021 Michael Ablassmeier + Copyright (C) 2023 Michael Ablassmeier 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 @@ -20,10 +20,10 @@ import sys import tempfile import logging import argparse -from argparse import Namespace -from typing import List, Union, Dict import pprint import json +from argparse import Namespace +from typing import List, Union, Dict from libvirtnbdbackup import argopt from libvirtnbdbackup import __version__ from libvirtnbdbackup import nbdcli @@ -32,7 +32,7 @@ from libvirtnbdbackup import chunk from libvirtnbdbackup import lz4 from libvirtnbdbackup.qemu import util as qemu from libvirtnbdbackup import output -from libvirtnbdbackup.common import common as lib +from libvirtnbdbackup import common as lib from libvirtnbdbackup.logcount import logCount from libvirtnbdbackup.sparsestream import streamer from libvirtnbdbackup.sparsestream import types @@ -359,15 +359,6 @@ def readConfig(ConfigFile: str) -> str: raise -def getDisksFromConfig( - args: Namespace, vmConfig: str, virtClient: virt.client -) -> List[DomainDisk]: - """Parse disk information from latest config file - contained in the backup directory - """ - return virtClient.getDomainDisks(args, vmConfig) - - def checkBackingStore(args: Namespace, disk: DomainDisk) -> None: """If an virtual machine was running on an snapshot image, warn user, the virtual machine configuration has to be @@ -416,7 +407,7 @@ def restore(args: Namespace, ConfigFile: str, virtClient: virt.client) -> bytes: """Handle restore operation""" stream = streamer.SparseStream(types) vmConfig = readConfig(ConfigFile) - vmDisks = getDisksFromConfig(args, vmConfig, virtClient) + vmDisks = virtClient.getDomainDisks(args, vmConfig) if not vmDisks: raise RestoreError("Unable to parse disks from config")