Cloud World

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 31 October 2013

Compute Engine Persistent Disk Backups using Snapshots

Posted on 07:00 by Unknown
Persistent Disks in Google Compute Engine allow you to take point-in-time snapshots of your disks. Once a snapshot is taken, it’s globally available and can be restored to any zone, even if the zone where the disk was originated is hit by a meteor. On top of that, it’s easy to create and manage snapshots. These two features make snapshots very appealing as a backup solution. However, there are some details you need to take into account in order to use snapshots safely for backup.



First, let’s take a peek on how snapshots work. A snapshot is an exact copy of your disk at a point in time. A snapshot can be taken at the same time reads and writes are happening to the disk. In physical terms, it’s like stopping the disk head while the disk is in use and copying all disk sectors out, except that, thanks to Persistent Disk design, it takes only a fraction of a second to create the snapshot. The rest of the time is spent uploading the bits to Google Cloud Storage and there is no performance impact to your disks.



Snapshots are guaranteed to be consistent at the block level (block size=4KiB). This means that snapshots never contain a partially written block (no torn writes). However, if application is making a write operation that spans multiple blocks, it’s possible that only the first portion of the write operation is stored in the snapshot. In addition, writes made to the file system cache will not be present in the snapshot, meaning a snapshot is equivalent to a disk that underwent an unclean shutdown. While most file systems and server applications can handle this just fine (due to journaled file systems, redo logs, etc.), it may require time-consuming steps to restore the disk back to a consistent state. Certain applications may not be able to handle this situation gracefully.



There are a few simple steps you can take to ensure your snapshot is consistent. First, we strongly recommend using mounted volumes for application data (not boot disk). Among other things, it’s easier and safer to take snapshots in a running instance. These are the steps you need to follow before snapshots are taken:

  1. Pause IOs coming from the application if possible. Certain applications have explicit commands to pause and resume IOs, e.g. Oracle, MySQL. If your application doesn’t support pause/resume, make sure that your application can survive unclean shutdowns (e.g. MongoDB).

  2. Flush the file system cache (sync), and

  3. Pause IOs coming from file system. You can use fsfreeze command for Ext3/4, ReiserFS, JFS, and XFS.

Once there are no more IOs being sent to disk, it’s safe to start the snapshot. Note that IOs need to be paused for just the fraction of second that it takes to create the snapshot. IO operations can then be resumed while snapshot data is copied to Cloud Storage in the background.



Here is an example where we snapshot the disk “my-disk” using gcutil tool:

> # freeze IOs in application
> sudo sync
> sudo fsfreeze -f /mnt/my-disk
> gcutil addsnapshot --source_disk=my-disk my-snapshot --nosynchronous_mode


After issuing those commands, we wait until the snapshot operation transitions to either UPLOADING or READY state:

> gcutil getsnapshot my-snapshot
+----------------------+-------------------------------+
| name | my-snapshot |
| description | |
| creation-time | 2013-09-30T19:34:24.354-07:00 |
| status | UPLOADING |
| disk-size-gb | 10 |
| storage-bytes | 3802018 |
| storage-bytes-status | UP_TO_DATE |
| source-disk | disks/my-disk |
+----------------------+-------------------------------+


We can now safely resume IOs to the disk while the upload process completes in the background:

> sudo fsfreeze -u /mnt/my-disk
> # resume IOs in application


To restore the snapshot, wait until snapshot operation completes, and execute:

> gcutil adddisk --source_snapshot=my-snapshot my-disk-copy


Mount your disk and verify that it is working as expected. I can’t stress enough how important it is to test your backups regularly and to ensure your backup procedure is correct.



Once your application data is successfully backed up, you may still want to backup the root volume to save machine configuration and tools that you have installed. It’s not safe to use fsfreeze against your root volume because any command that requires write access to disk will be blocked. For example, logging on to a machine requires write access to disk, therefore you might get locked out if your ssh session disconnects while root is frozen. The safest way to snapshot root volume is to shut down your instance and then take the snapshot. If that is not possible, reduce the number of writes to root as much as possible to reduce recovery time, and take the snapshot. Your journaled file system will be able to recover safely after your disk is restored.



-Posted by Fabricio Voznika, Software Engineer
Email ThisBlogThis!Share to XShare to Facebook
Posted in Compute Engine | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Bridging Mobile Backend as a Service to Enterprise Systems with Google App Engine and Kinvey
    The following post was contributed by Ivan Stoyanov , VP of Engineering for Kinvey, a mobile Backend as a Service provider and Google Cloud ...
  • Tutorial: Adding a cloud backend to your application with Android Studio
    Android Studio lets you easily add a cloud backend to your application, right from your IDE. A backend allows you to implement functionality...
  • 2013 Year in review: topping 100,000 requests-per-second
    2013 was a busy year for Google Cloud Platform. Watch this space: each day, a different Googler who works on Cloud Platform will be sharing ...
  • Easy Performance Profiling with Appstats
    Since App Engine debuted 2 years ago, we’ve written extensively about best practices for writing scalable apps on App Engine. We make writ...
  • TweetDeck and Google App Engine: A Match Made in the Cloud
    I'm Reza and work in London, UK for a startup called TweetDeck . Our vision is to develop the best tools to manage and filter real time ...
  • Scaling with the Kindle Fire
    Today’s blog post comes to us from Greg Bayer of Pulse , a popular news reading application for iPhone, iPad and Android devices. Pulse has ...
  • Who's at Google I/O: Mojo Helpdesk
    This post is part of Who's at Google I/O , a series of guest blog posts written by developers who are appearing in the Developer Sandbox...
  • A Day in the Cloud, new articles on scaling, and fresh open source projects for App Engine
    The latest release of Python SDK 1.2.3, which introduced the Task Queue API and integrated support for Django 1.0, may have received a lot ...
  • SendGrid gives App Engine developers a simple way of sending transactional email
    Today’s guest post is from Adam DuVander, Developer Communications Director at SendGrid. SendGrid is a cloud-based email service that deliv...
  • Qubole helps you run Hadoop on Google Compute Engine
    This guest post comes form Praveen Seluka, Software Engineer at Qubole, a leading provider of Hadoop-as-a-service.  Qubole is a leading pr...

Categories

  • 1.1.2
  • agile
  • android
  • Announcements
  • api
  • app engine
  • appengine
  • batch
  • bicycle
  • bigquery
  • canoe
  • casestudy
  • cloud
  • Cloud Datastore
  • cloud endpoints
  • cloud sql
  • cloud storage
  • cloud-storage
  • community
  • Compute Engine
  • conferences
  • customer
  • datastore
  • delete
  • developer days
  • developer-insights
  • devfests
  • django
  • email
  • entity group
  • events
  • getting started
  • google
  • googlenew
  • gps
  • green
  • Guest Blog
  • hadoop
  • html5
  • index
  • io2010
  • IO2013
  • java
  • kaazing
  • location
  • mapreduce
  • norex
  • open source
  • partner
  • payment
  • paypal
  • pipeline
  • put
  • python
  • rental
  • research project
  • solutions
  • support
  • sustainability
  • taskqueue
  • technical
  • toolkit
  • twilio
  • video
  • websockets
  • workflows

Blog Archive

  • ▼  2013 (143)
    • ►  December (33)
    • ►  November (15)
    • ▼  October (17)
      • Compute Engine Persistent Disk Backups using Snaps...
      • Google Cloud SQL is now accessible from just about...
      • Learn about building global applications on Google...
      • Five Options for Cloud to Cloud Data Migration
      • Google App Engine for PHP with PhpStorm
      • Total Eclipse of the Apps Script
      • App Engine 1.8.6 released
      • R/GA shares why digital agencies are turning to th...
      • Unlocking Big Data
      • The new Cloud Console: designed for developers
      • New features and tutorials for Compute Engine Load...
      • Speed up iOS development with Google Cloud Platform
      • Google App Engine PHP Runtime now available to eve...
      • How to get auto scaling of Google Compute Engine "...
      • The Cloud Platform Support team is here to help
      • One platform, many uses
      • Jump-start your data pipelining into Google BigQuery
    • ►  September (13)
    • ►  August (4)
    • ►  July (15)
    • ►  June (12)
    • ►  May (15)
    • ►  April (4)
    • ►  March (4)
    • ►  February (9)
    • ►  January (2)
  • ►  2012 (43)
    • ►  December (2)
    • ►  November (2)
    • ►  October (8)
    • ►  September (2)
    • ►  August (3)
    • ►  July (4)
    • ►  June (2)
    • ►  May (3)
    • ►  April (4)
    • ►  March (5)
    • ►  February (3)
    • ►  January (5)
  • ►  2011 (46)
    • ►  December (3)
    • ►  November (4)
    • ►  October (4)
    • ►  September (5)
    • ►  August (3)
    • ►  July (4)
    • ►  June (3)
    • ►  May (8)
    • ►  April (2)
    • ►  March (5)
    • ►  February (3)
    • ►  January (2)
  • ►  2010 (38)
    • ►  December (2)
    • ►  October (2)
    • ►  September (1)
    • ►  August (5)
    • ►  July (5)
    • ►  June (6)
    • ►  May (3)
    • ►  April (5)
    • ►  March (5)
    • ►  February (2)
    • ►  January (2)
  • ►  2009 (47)
    • ►  December (4)
    • ►  November (3)
    • ►  October (6)
    • ►  September (5)
    • ►  August (3)
    • ►  July (3)
    • ►  June (4)
    • ►  May (3)
    • ►  April (5)
    • ►  March (3)
    • ►  February (7)
    • ►  January (1)
  • ►  2008 (46)
    • ►  December (4)
    • ►  November (3)
    • ►  October (10)
    • ►  September (5)
    • ►  August (6)
    • ►  July (4)
    • ►  June (2)
    • ►  May (5)
    • ►  April (7)
Powered by Blogger.

About Me

Unknown
View my complete profile