Skip to content

add --auto-full-ratio option for size based backup chains - #36

Merged
abbbi merged 2 commits into
abbbi:masterfrom
lukenowak:auto-full-ratio
Aug 17, 2026
Merged

abbbi merged 2 commits into
abbbi:masterfrom
lukenowak:auto-full-ratio

Conversation

@lukenowak

@lukenowak lukenowak commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

An incremental backup chain only grows, and a virtual machine which rewrites its
disk saves the same blocks over and over, so the chain eventually occupies more
space than the disk image itself.

With backup level auto, --auto-full-ratio starts a new chain with a full backup
as soon as the existing chain of any included device outgrows the given multiple
of the space a full backup of that device requires.

The chain is measured against what a full backup costs rather than against the
disk image size alone: a full backup of a small or sparsely allocated disk is
bigger than the space the image occupies, so the image size alone would start a
new chain costing more than the one it replaces.

--auto-full-remove-chain, off by default, removes the chain before the full
backup replacing it is written. A target sized after the disk image is the least
likely to have room for both, exactly because the chain outgrew the image. Should
that full backup then fail, the target is left without a restorable backup, so
the option stays opt-in.

Fixes #35

@lukenowak
lukenowak force-pushed the auto-full-ratio branch 2 times, most recently from 28a8a26 to c8d0e96 Compare August 7, 2026 07:37
An incremental backup chain only grows, and a virtual machine which
rewrites its disk saves the same blocks over and over, so the chain
eventually occupies more space than the disk image itself.

With backup level auto, --auto-full-ratio starts a new chain with a full
backup as soon as the existing chain of any included device outgrows the
given multiple of the space a full backup of that device requires.

The chain is measured against what a full backup costs rather than
against the disk image size alone: a full backup of a small or sparsely
allocated disk is bigger than the space the image occupies, so the image
size alone would start a new chain costing more than the one it replaces.
@lukenowak

Copy link
Copy Markdown
Contributor Author

One thing worth flagging: the --no-subdir path of get_chain() has no
regression test.

With --no-subdir all devices share one target directory, and the chain was
picking up other devices' backups plus the uuid/*.config files, while
dropping the device's own FULL (chain_start came from whichever device's FULL
happened to be written last). That is fixed by matching only FULL-*-<disk> /
INC-*-<disk>, and I verified it directly against get_chain().

I could not turn it into a reliable t/runtest case: with every disk in one
directory the outcome depends on which device's FULL is written last and on
increment sizes that vary with guest activity, so the test passes or fails for
reasons unrelated to the fix. Happy to add one if you see a stable way to
express it, or to add a small unit test if you would take a test module
alongside the shell suite.

@lukenowak
lukenowak marked this pull request as ready for review August 7, 2026 08:22
@lukenowak
lukenowak marked this pull request as draft August 10, 2026 08:02
--auto-full-ratio keeps the chain it replaces, so the target has to hold
that chain and the new full backup at the same time. A target sized
after the disk image is the least likely to have room for both, exactly
because the chain outgrew the image.

Removing the chain before the full backup is written costs the only
restorable backup in the target should that backup fail, so it stays
opt-in.
@lukenowak

Copy link
Copy Markdown
Contributor Author

I've added a feature to this PR which comes from our usage of qmpbackup -- the predelete.

Generally this code passed also our CI, but I haven't tested it in real setup yet.

It's up to you @abbbi if you want me to reassure deeper the functionality, or you are ok with merging this in current state. As usually bugs might come in the future.

@lukenowak
lukenowak marked this pull request as ready for review August 10, 2026 14:48
@lukenowak

Copy link
Copy Markdown
Contributor Author

Generally this code passed also our CI, but I haven't tested it in real setup yet.

I made tests in real setup and it correctly kicked in:

main: Version: 0.67 Arguments: <SOFT>/bin/qmpbackup --socket <INST>/var/run/qmp_socket backup --compress --target <INST>/srv/backup/kvm --include virtio0 --auto-full-ratio 0.01 --auto-full-remove-chain --level auto
main: Connecting QMP socket: [<INST>/var/run/qmp_socket]
show_vm_state: VM is in state: [running]
show_version: Qemu version: [10.0.2] []
show_name: VM Name: [kvm0]
main: Backup target directory: <INST>/srv/backup/kvm
main: Auto backup mode set to: inc
main: Enabling compress option for backup operation.
get_uuid: Current Backup UUID: [fd6436bb-6c3f-46d6-b52f-6f1bfcc6e540] for folder [<INST>/srv/backup/kvm]
get_block_devices: Child device detected but uses block notation, ignoring.
get_block_devices: Excluding device with raw format from backup: [ide0-cd0:<INST>/srv/boot-image-url-select-repository/10484b2d8e2780801dc7d354ba4ff238]
main: [virtual1:virtual.qcow2] Backup chain of [25022631662] bytes exceeds [0.01] times the full backup size of [28509933568] bytes: full backup required.
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/FULL-1786454606-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786454978-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786455088-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786455600-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786456434-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786460483-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786516010-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786517214-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786525575-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786525598-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786525628-virtual.qcow2]
main: Removing replaced backup: [<INST>/srv/backup/kvm/virtual.qcow2/INC-1786529883-virtual.qcow2]
save_info: Saved image info: [<INST>/srv/backup/kvm/virtual.qcow2.config]
create: Create target backup image: [<INST>/srv/backup/kvm/virtual.qcow2/FULL-1786534489-virtual.qcow2.partial], virtual size: [42949672960]
create: Create fleece image: [<INST>/srv/FULL-1786534489-virtual1.fleece.qcow2], virtual size: [42949672960]
prepare_target_devices: Attach backup target devices to virtual machine
prepare_fleece_devices: Attach fleece devices to virtual machine
add_cbw_device: Adding cbw devices to virtual machine
blockdev_replace: Activate copy-before-write filter
add_snapshot_access_devices: Add snapshot-access devices.
prepare_transaction: Clearing existing bitmap: [qmpbackup-fd6436bb-6c3f-46d6-b52f-6f1bfcc6e540] using node [virtual1]: [virtual.qcow2]
backup: Started backup transaction for [1] devices
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 4% (1606549504 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 8% (3234856960 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 12% (5127995392 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 16% (6793396224 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 19% (8311209984 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 24% (10133831680 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 28% (11835342848 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 31% (13520928768 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 35% (15028453376 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 39% (16709648384 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 43% (18437308416 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 51% (22082682880 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 55% (23833083904 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 59% (25475678208 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 64% (27325497344 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 67% (28990963712 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 71% (30518280192 of 42949672960)
progress: [qmpbackup.virtio0.virtual.qcow2] Wrote Offset: 74% (31933988864 of 42949672960)
backup: Block job [qmpbackup.virtio0.virtual.qcow2] finished
backup: Backup for all [1] devices finished.
remove_snapshot_access_devices: Removing snapshot-access devices from virtual machine
blockdev_replace: Disable copy-before-write filter
remove_cbw_devices: Removing cbw devices from virtual machine
remove_target_devices: Removing backup target devices from virtual machine
remove_fleece_devices: Removing fleece devices from virtual machine
main: Renaming partial files
remove_fleece_files: Removing fleece image files

@abbbi
abbbi merged commit bf4060f into abbbi:master Aug 17, 2026
1 check passed
@lukenowak
lukenowak deleted the auto-full-ratio branch August 31, 2026 08:44
@lukenowak

Copy link
Copy Markdown
Contributor Author

@abbbi I wonder when you plan to release new version with the added feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Size based backup chains: start a new full backup when the chain outgrows the disk image

2 participants