Snapshot
Snapshot

Reputation: 113

Correct way to take a snapshot

I've asked this question before, but I am still confused. What's the correct and quickest way to take a snapshot (I only use EBS-backed Unix and Windows machines, so that's all my interest right now). Some ideas:

Hope you EC2 experts can help me.

Upvotes: 7

Views: 2907

Answers (3)

Christopher McGowan
Christopher McGowan

Reputation: 1391

Quick answer - both operating systems have features for safely unmounting the drive. An unmounted drive can be snapshotted without fear of corruption.

Long answer An EBS snapshot is point-in-time and differential (it does not "copy" your data per-se), so as long as your drive is in a consistent and restorable state when it begins, you'll avoid the corruption (since the snapshot is atomic).

As you have implied, whatever state the whole drive is in when it starts, that's what your snapshot image will be when it is restored (if you snapshot while you are half-way done writing a file, then, by-golly, that file will be half-written when you restore).

For both Linux and Windows, a consistent state can be this can be acheived by unmounting the drive. This will guarantee that your buffers are flushed to disk and no writes can occur. In both linux and windows there are commands to list which processes are using the drive; once you have stopped those processes or otherwise gotten them to stop marking the drive for use (different for each program/service), you can unmount. In windows, this is very easy by setting your drive as a "removable drive" and then using the "safely remove hardware" feature to unmount. In linux, you can unmount with the "umount" command.

There are other sneakier ways, but the above is pretty universal.

So assuming you get to a restorable state before you begin, you can resume using your drive as soon as the snapshot starts (you do not need to wait for the snapshot completes before you unlock (or remount) and resume use). At that point you can remount the volume.

How AWS snapshot works:

Your volume and the snapshot is just a set of pointers, when you take a snapshot, you just diverge any blocks that you write to from that point forward; they are effectively new blocks associated with the volume, and the old blocks at that logical place in the volume are left alone so that the snapshot stays the same logically.

This is also why subsequent snapshots will tend to go faster (they are differential).

http://harish11g.blogspot.com/2013/04/understanding-Amazon-Elastic-block-store-EBS-snapshots.html

Upvotes: 2

Till
Till

Reputation: 22408

Taking a snapshot often requires scheduled downtime.

Procedure:

  1. I'd unmount the drive.
  2. Start the snapshot and wait until it's done.
  3. And then re-mount it.

Afaik, the only viable way for a consistent snapshot.

If you could share more about what kind of data is on the snapshot (e.g. a database?), then I could probably extend my answer.

I cannot comment on Windows-based instances since I'm not at all familiar with it but in order to avoid redundancy, check out this blog entry explains as it explains a lot:

In a nutshell, they use the xfs file system and when they freeze it to create the snapshot, they allow updates to the filesystem to pass. According to the comments, it seems to work for most people.

Upvotes: 0

James
James

Reputation: 1150

If a bit of data loss is acceptable, just take the snapshot while the instance is running. If it's not acceptable, write some script magic to ensure everything your application is working on is saved to disk, take the snapshot, then let your app resume work.

For what I do, I find it best to keep a separate EBS volume with my application and its data on it, and when I need a snapshot, I just stop the app for a moment, snapshot, and fire it back up. That way you don't have to worry about what the OS is doing during the snapshot, and it also comes with the added bonuses of being able to quickly move your app and its data to more powerful hardware, and having much smaller snapshots.

Upvotes: 3

Related Questions