How can a backup snapshot be taken when server is running?
How can Linode take a snapshot of the server while the server is running? Let's say, for example, that I have a web application that processes user requests, stores data in a database, and has a high amount of traffic.
When I begin to take a backup snapshot, the server is in a certain state. It may begin to copy data on disc starting at the beginning of the disk, and copying sequentially to the backup snapshot location. However, as the snapshot is being taken, the data on disk is constantly changing as user requests are coming in many times per second and the data in the database is changing. So by the time the snapshot is "complete," the state of the server has changed completely.
So exactly which state is backed up? It seems as if, logically, it can't be the state at the beginning or the end, so it must be some state in the middle.
But what if a user request modifies data in two different locations on disk, one that has already been copied over to the snapshot and one that has yet to be copied? The result is that the backup snapshot would contain the "old" data at the first location, but the "newer" data in the second location. The result is that the database or disk state is now inconsistent! This could potentially completely break the integrity of the database or web application.
So I guess what I'm asking is it seems that the only way a snapshot could be taken while the server is running is if it is taken instantaneously. But that is clearly not the case. So how can Linode do these backup snapshots while maintaining data integrity?
Thanks for anyone who can shed light on this!
6 Replies
I believe Linode's backups are file-based and not block-based, so I'm not sure how this would change the backup process. It might work completely differently from how I described above, but that at least gives you some idea of how it can be done.
So, a common way to host Xen virtual machines is with LVM rather than disk files such as what you'd see with VMWare's datastore. LVM is the logical volume manager and it allows you to provision disk devices from pools. You create a partition on your hard disk and assign it to LVM, and then you make other volumes from that space using LVM commands.
LVM supports snapshots, which are exactly what it says on the tin. You run lvcreate a certain way and the kernel figures out all the magic to give you a separate device file that is the snapshot you took at the point you typed the command. At that point, Linode can mount that disk volume and do their own file-based magic to give you the backup slots. I'd suspect they use simple scripts and rsnapshot, but I really have no clue. Meanwhile, the regular VM will keep writing to the original LVM volume and the snapshot volume can be deleted once the backup is done.
@Guspaz:
Well, they are and they aren't.
But you can't tell until the backup actually occurs. Then, that cat in the box will tell you.