non-destructive zero, convert, compress via pipe?

Discussions related to using VirtualBox on Linux hosts.
Post Reply
kurtharriger
Posts: 5
Joined: 17. Nov 2008, 01:52

non-destructive zero, convert, compress via pipe?

Post by kurtharriger »

One of the nice things about virtual machines is that backups are as easy as file copy. I often preferred to keep them uncompressed so I can more quickly revert to an old image, but sometimes I'll gzip older images to save space.

For performance, however, I switched to a fixed size vdi and I think I'm going to start always compressing them and thought I would just write a shell script more efficiently backup my virtual disk. What I would like to do:

1) NON-DESTRUCTIVELY zero the unused disk space
2) compact/clonehd to dynamic sizing disk
3) gzip to file with date stamp.

Ideally the script would minimize temporary files using pipes, but I'm not sure this is possible.
Unfortunately, I need to run windows vista in a VM (at least its not my host), so my VM file system is NTFS.

I have seen several posts that mention using sdelete to zero the free space prior to compacting a vdi file, and to get the most from compression I would want to zero out the unused space -- however, I am making a backup and it is important to me that the backup process does not in any way alter what is being backed up, if the process mutates the VDI it should first make a copy, then mutate it.

Step 1 seems like the hardest part as most things I can find require you run this step on the guest before performing the compact step. I was thinking however I might be able to mount the VDI file with vdifuse and use ntfsclone non-destructively copy only the used portion the filesystem, but this would just copy the file system not the vdi file. I'm thinking I could probably create a new vdi, mount it with vdi fuse, and restore the ntfs image. Unfortunately even if this works I don't see how I could pipe the resulting vdi to gzip. So I might just skip this step or use sdelete, but it would be really cool if there was a way to do this.

For Step 2, I assume that using clonehd to dynamic size disk would be same as compacting the existing image. Arguably I could probably skip the conversion to dynamic disk since after compression the resulting file should be just as small, however, I always seem to have less free space when I want to restore a large file so I would prefer to uncompress it into a smaller file and then if I want reconvert it to a fixed image I figure I can do it then. The part I'm not to sure about here is if it is possible to pipe the output of clonehd into gzip so I don't need to create 60G temp files. I don't believe that clonehd has an option to write to stdout, but I do believe its possible to create a custom named pipe and write to that, should work ya?

Anyone ever done anything like this before? I came up with a few ideas as I was writing this out so I'll have a go at it. If anyone has any ideas on step 1 love to hear it.

Thanks!
Post Reply