normalian blog

Let's talk about Microsoft Azure, ASP.NET and Java!

Web サイトのバックアップ/復元 機能を利用してみる

Azure: ExpressRoute Dedicated Networking, Web Site Backup Restore, Mobile Services .NET support, Hadoop 2.2, and more にて発表された Webサイトのバックアップ/復元機能が便利そうだったのでちょっと触ってた。

まず簡単なWEBアプリを作る

Node.js で簡単にテーブル操作する処理を以下の様に実装した。今回は Node.js アプリ& git デプロイした場合のフォルダ構成となる点だけ認識頂ければ幸いだ。

  • server.js
var http = require('http')
var port = process.env.PORT || 1337;

var azure = require('azure');
var ServiceClient = azure.ServiceClient;
var TableQuery = azure.TableQuery;
var tableClient = azure.createTableService("<ストレージアカウント名>",
 "<ストレージアカウントキー>",
 "http://<ストレージアカウント名>.table.core.windows.net/");

var tableName = 'posts';
var partition = 'part1';
var rowkey = 'bbbbbb';

http.createServer(function(req, res) {
  tableClient.createTableIfNotExists(tableName, function (err, created) {
      var now = new Date().toGMTString();
      var entity = {
          PartitionKey: partition,
          RowKey: rowkey + now,
          title: 'Post one',
          body: 'Body one at WebSite',
          created_at: now };
      tableClient.insertEntity(tableName, entity, null, function(err){
         console.log(err);
      });
  });

  res.writeHead(200, { 'Content-Type': 'text/html; charset=UTF-8' });
  res.end('無事にテーブルストレージにインサートした模様\n');
}).listen(port);

以下のコマンドでモジュールをインストール後、git push してアプリケーションを動作させる。

npm install azure 
git add .
git commit -m "commit"
git push <hogehoge>

バックアップを試す

Webサイトの管理画面から「バックアップ プレビュー」のタブがあるので選択する。「標準モード」でしか利用できないので、注意が必要だ。
f:id:waritohutsu:20140304011118j:plain

自動化されたバックアップを頻度を含め設定できるほか、何処のストレージサービスに格納するかを設定できる。
f:id:waritohutsu:20140304011144j:plain

「今すぐバックアップ」を選択すると選択したストレージサービスにデータが格納される。ストレージサービスに「websitebackups」フォルダが作成され、「_<日付>」フォーマットの xml ファイルと zip ファイルが格納されている。
f:id:waritohutsu:20140304011207j:plain

  • normalianbkup_201403031549.xml
<?xml version="1.0" encoding="utf-8"?>
<BackupDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
  <Version>0</Version>
  <Name><Webサイト名>_<日付></Name>
  <HostNames xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <d2p1:string><Webサイト名>.azurewebsites.net</d2p1:string>
  </HostNames>
  <Databases />
</BackupDescription>
  • normalianbkup_201403031549.zip ファイルの中身
normalianbkup_201403031549.zip
└─fscontent
   ├─LogFiles
   │  └─Git
   │      └─trace
   └─site
       ├─deployments
       │  ├─9e3f836b7daa0648bb95a9371f3fd748d
       │  └─tools
       ├─repository
       │  └─.git
       └─wwwroot
           └─node_modules

zip ファイル側は site 以下のファイルがまるっと zip に固められていることがわかる。

復元を試す

「今すぐ復元」を選ぶとどのバックアップファイルからWebサイトを復元するか選択可能だ。
f:id:waritohutsu:20140304011637j:plain

また、復元先はもともとのWebサイトはもちろん、新たなWebサイトを作成してバックアップすることも可能だ。
f:id:waritohutsu:20140304011648j:plain