Imaging mounted disk volumes under duress
blog.benjojo.co.uk
blog.benjojo.co.uk
[Also if you are playing with custom block devices in Linux -- mounted or otherwise but not /dev/sda -- https://gitlab.com/nbdkit/nbdkit https://libguestfs.org/nbdkit.1.html One filter we have which is kind of similar to blktrace is called the nbdkit-stats-filter https://libguestfs.org/nbdkit-stats-filter.1.html]
If you ever cared it's easy enough to clone one of those snapshots and bring it up as another DB instance to poke around at how things used to be...
PostgreSQL on ZFS is great.
I have zstd compression enabled and I average 3.50x compression ratios.
(Probably some pretty awful CPU tradeoffs in there, but system load and query times seem fine. My database is 50 GB before zstd compression, so enabling it helps a ton.)
I also have ZFS snapshots taken hourly and shipped offsite. It's awesome that I don't need to pause PostgreSQL or anything to take the snapshot. It's atomic and instant.
I assume this is to prevent situations that would need time-intensive WAL-replay or such, and there it'd only be opportunistic with the "sudden power loss" recovery as a fall-back path.
More interesting is e.g. Hyper-V using this to snapshot the guest VMs.
It just takes you one step beyond being only crash-consistent, so that everything is actually application-consistent.
Implementing a VSS writer is a big 90's-style COM interface, but there is also a lightweight alternative model on top of that that eludes my search right now.
Red Hat has some similar convention for freeze/thaw scripts that can make API calls to the DB to ask it to do the same thing.
It can run through VMware tools into virtual machines, too, and down a layer to SAN storage and trigger a SAN snapshot so that a backup system like Veeam can take data from the SAN while knowing the guests two levels higher flushed data before the snapshot was taken.
or e.g. here Nimble SAN can talk up to servers through VSS to trigger SQL Server quiesce before they take a SAN snapshot: https://infosight.hpe.com/InfoSight/media/cms/active/public/...
https://www.postgresql.org/docs/8.1/backup-online.html
These database already have to make sure that they can recover from the system crashing. So it is probably only incrementally more work to add a feature to write out some extra metadata to enable these sorts of online backups.
Disclaimer: I'm a software engineer at Datto.
Have you asked upstream what they think of it, at all?
But VSS, like LVM or other snapshoting FS, requires dedicated FS support. You don't have VSS on FAT32. Here, blktrace works at block device level, so does not rely on any FS support.
That's also what the article says: If you have LVM, you don't need any special tool.
However, it does signal to the filesystem, quoting https://manned.org/fsfreeze.8 :
fsfreeze is unnecessary for device-mapper devices. The device-mapper (and
LVM) automatically freezes a filesystem on the device when a snapshot
creation is requested. For more details see the dmsetup(8) man page.I guess MS-SQL does something similar, and that does seem useful beyond what LVM does.
Also VSS apparently can offload the snapshotting to a SAN ('VSS Hardware Provider'): https://docs.microsoft.com/en-us/windows-server/storage/file...
---
I've been looking for a way to copy virtual machine disks over the network with minimal downtime.
I.e. Copy the entire 50 GB disk over. Suspend the VM. Do a quick pass that picks up the changed blocks. Resume the VM.
Does anyone have a tool for that? It would be similar to how QEMU/KVM does it for VM migrations. (They only support doing it for RAM though.)
---
Also related, you can use the sysrq feature on Linux to remount the root file system as read-only. Then run `dd if=/dev/sda | ssh user@destination.com 'cat > sda.img'` to transfer the root partition consistently.
I've used this twice to migrate VPSs off of Cloud providers and onto my physical servers to convert to .qcow2 images. Worked perfectly :)
I'm not sure if you are required to reboot afterwards, but I always do. It would be nice to "un sysrq remount".
I don't know of anything wrapping it, but if I was doing that I'd just put it on ZFS (handing zvols to qemu as disks) and then do incremental snapshots and send-recv them. (Bonus: trivial inline compression, and if you `zfs send --raw` even the transfer will be compressed)
The --raw/-w flag does send the compressed data.
It always feels brittle to me because of how manual the process is. Maybe it's time to create some decent scripts with safe logic and checks...
https://lwn.net/Articles/837053/
Also you can always do the fsfreeze yourself (which is what qemu agent can do, and is used by proxmox backup server).
However, if you just have a page modification flag then if you try and recopy the data that has been modified then it seems like you could just end up in a loop where you make no progress because the disk is continually being modified. If none of the modified pages have been modified during your second pass then everything is ok but if some have been modified then that could invalidate other pages that have weren’t modified during the first pass but we’re modified during the second pass.
As long as the system was only under normal near-idle load, there will be some modifications, but not too many, so you'll be able to catch up much more quickly, leaving the window for new modifications even smaller.
Of course, if the disk is continuously receiving a high write volume, the race might never end. But if it's idle long enough for you to do a sync and a final collection pass before the next write, you'll have a full image.
Generally, the way VM migrations deal with this is by suspending the VM once a small enough set of dirty pages remain. I think the same can be done with block devices on Linux; if I remember correctly, there's some file in sysfs that you can poke to quiesce a block device. Just make sure your app is fully in RAM/cache, ideally locked, if you do this to your root filesystem :)
[1] https://github.com/benjojo/hot-clone/blob/6a019efe28bdbbeeb1...
[2] https://github.com/benjojo/hot-clone/blob/6a019efe28bdbbeeb1...
But yeah, the consistency test doesn't match the real scenario...
I guess it may work on a live filesystem if you iteratively ever get to a point that after reading the changed data you don't get any new changes in the trace and stop right there.
Repeatedly copying until there are no new changes would produce a consistent image (if it terminates -- it requires the writing speed to the output device to be faster than the rate at which new data is being written to the input disk).
It may possible to stop earlier. The precise condition for producing a consistent image is as follows:
Let A[i] be the most recent modification time of block i, let B[i] be the modification time of block i at the time it was copied, and let C[i] be the time of the first modification to block i after it was copied (or infinity if the block hasn't been modified since it was copied).
We can stop if max(B) < min(C).
In detail, here is how to compute A, B, and C:
1. Initially, A[i] = B[i] = C[i] = 0.
2. When we are notified that block i has been altered, set A[i] to the modification timestamp. If C[i] == infinity, set C[i] to A[i].
3. When we copy block i, set B[i] to A[i] and set C[i] to infinity.
I would take this guy as a coworker any day. Excellent real world awareness, practicality, only reinventing the bolts of one wheel, and excellent explanation of what and why.