Skip to content

Commit

Permalink
add option --preallocate to virtnbdrestore
Browse files Browse the repository at this point in the history
  • Loading branch information
abbbi committed Aug 25, 2024
1 parent db5496f commit df84146
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 2.14
---------
* virtnbdrestore: Add option -A (--preallocate) to create thick, full
pre-allocated target images during restore.

Version 2.13
---------
* virtnbdbackup: If libvirt daemon is unreachable, it would fail with an
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ in the output directory `/tmp/restore`
> 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.
`Note`:
> Created disk images will be thin provisioned by default, you can change this
> behavior using option `--preallocate` to create thick provisioned images.
## Process only specific disks during restore

A single disk can be restored by using the option `-d`, the disk name has
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__ = "2.13"
__version__ = "2.14"
7 changes: 6 additions & 1 deletion libvirtnbdbackup/qemu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def map(cType) -> str:
return json.loads(extentMap.stdout)

@staticmethod
def create(
def create( # pylint: disable=R0913: disable=R0913
args: Namespace,
targetFile: str,
fileSize: int,
diskFormat: str,
Expand All @@ -74,6 +75,10 @@ def create(
f"size={fileSize}",
]

if args.preallocate:
cmd.append("-o")
cmd.append("preallocation=full")

if qcowOptions:
cmd = cmd + qcowOptions

Expand Down
10 changes: 8 additions & 2 deletions libvirtnbdbackup/restore/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ def getConfig(args: Namespace, meta: Dict[str, str]) -> List[str]:
def create(args: Namespace, meta: Dict[str, str], targetFile: str, sshClient):
"""Create target image file"""
logging.info(
"Create virtual disk [%s] format: [%s] size: [%s] based on: [%s]",
"Create virtual disk [%s] format: [%s] size: [%s] based on: [%s] preallocated: [%s]",
targetFile,
meta["diskFormat"],
meta["virtualSize"],
meta["checkpointName"],
args.preallocate,
)

options = getConfig(args, meta)
Expand All @@ -96,7 +97,12 @@ def create(args: Namespace, meta: Dict[str, str], targetFile: str, sshClient):
qFh = qemu.util(meta["diskName"])
try:
qFh.create(
targetFile, int(meta["virtualSize"]), meta["diskFormat"], options, sshClient
args,
targetFile,
int(meta["virtualSize"]),
meta["diskFormat"],
options,
sshClient,
)
except (ProcessError, sshError) as e:
logging.error("Failed to create restore target: [%s]", e)
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.49.3.
.TH VIRTNBDBACKUP "1" "August 2024" "virtnbdbackup 2.13" "User Commands"
.TH VIRTNBDBACKUP "1" "August 2024" "virtnbdbackup 2.14" "User Commands"
.SH NAME
virtnbdbackup \- backup utility for libvirt
.SH DESCRIPTION
Expand Down Expand Up @@ -52,7 +52,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.16504\/\fP)
Use specified file for NBD Server socket (default: \fI\,/var/tmp/virtnbdbackup.9548\/\fP)
.TP
\fB\-n\fR, \fB\-\-noprogress\fR
Disable progress bar
Expand Down
2 changes: 1 addition & 1 deletion man/virtnbdmap.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.49.3.
.TH VIRTNBDMAP "1" "August 2024" "virtnbdmap 2.13" "User Commands"
.TH VIRTNBDMAP "1" "August 2024" "virtnbdmap 2.14" "User Commands"
.SH NAME
virtnbdmap \- map virtnbdbackup image files to nbd devices
.SH DESCRIPTION
Expand Down
9 changes: 6 additions & 3 deletions man/virtnbdrestore.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.49.3.
.TH VIRTNBDRESTORE "1" "August 2024" "virtnbdrestore 2.13" "User Commands"
.TH VIRTNBDRESTORE "1" "August 2024" "virtnbdrestore 2.14" "User Commands"
.SH NAME
virtnbdrestore \- restore utility for libvirt
.SH DESCRIPTION
usage: virtnbdrestore [\-h] [\-a {dump,restore,verify}] \fB\-i\fR INPUT \fB\-o\fR OUTPUT
.TP
[\-u UNTIL] [\-s SEQUENCE] [\-d DISK] [\-n] [\-f SOCKETFILE]
[\-r] [\-c] [\-D] [\-C CONFIG_FILE] [\-N NAME] [\-B BUFFSIZE]
[\-U URI] [\-\-user USER] [\-\-ssh\-user SSH_USER]
[\-A] [\-U URI] [\-\-user USER] [\-\-ssh\-user SSH_USER]
[\-\-ssh\-port SSH_PORT] [\-\-password PASSWORD]
[\-P NBD_PORT] [\-I NBD_IP] [\-\-tls] [\-\-tls\-cert TLS_CERT]
[\-L LOGFILE] [\-\-nocolor] [\-v] [\-V]
Expand Down Expand Up @@ -41,7 +41,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.16509\/\fP)
Use specified file for NBD Server socket (default: \fI\,/var/tmp/virtnbdbackup.9553\/\fP)
.TP
\fB\-r\fR, \fB\-\-raw\fR
Copy raw images as is during restore. (default: False)
Expand All @@ -60,6 +60,9 @@ Define restored domain with specified name
.TP
\fB\-B\fR BUFFSIZE, \fB\-\-buffsize\fR BUFFSIZE
Buffer size to use during verify (default: 8192)
.TP
\fB\-A\fR, \fB\-\-preallocate\fR
Preallocate restored qcow images. (default: False)
.SS "Remote Restore options:"
.TP
\fB\-U\fR URI, \fB\-\-uri\fR URI
Expand Down
8 changes: 8 additions & 0 deletions virtnbdrestore
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def main() -> None:
type=int,
help="Buffer size to use during verify (default: %(default)s)",
)
opt.add_argument(
"-A",
"--preallocate",
default=False,
action="store_true",
help="Preallocate restored qcow images. (default: %(default)s)",
)

remopt = parser.add_argument_group("Remote Restore options")
argopt.addRemoteArgs(remopt)
logopt = parser.add_argument_group("Logging options")
Expand Down

0 comments on commit df84146

Please sign in to comment.