Amazon Glacierを使ってiPhotoの写真をバックアップしてみる(其の弐)
ファイルのアップロードを確認する
1日後にマネージメントコンソールをみてみると、ちゃんと2つのファイルがアップロード完了していることを確認できた。
High Level APIでファイルのダウンロードをしてみる
今度はダウンロードしてみる。High Level APIを使う方法とLow Level APIを使う方法があるが、とりあえずHigh Levelの方でやってみた。ダウンロードジョブが完了するまでの数時間の間、メソッドの呼び出しがかえってこなくなるらしい。
package myaws.glaceir; import java.io.File; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.services.glacier.AmazonGlacierClient; import com.amazonaws.services.glacier.transfer.ArchiveTransferManager; public class TestDownloadOperation { public static String vaultName = "xxxx"; public static String archiveId = "xxxx"; public static AmazonGlacierClient client; public static void main(String args[]) throws Exception{ AWSCredentials credentials = new PropertiesCredentials (TestDownloadOperation.class.getResourceAsStream("AwsCredentials.properties")); client = new AmazonGlacierClient(credentials); client.setEndpoint("https://glacier.ap-northeast-1.amazonaws.com"); try{ ArchiveTransferManager manager = new ArchiveTransferManager(client, credentials); long startTime = System.currentTimeMillis(); manager.download(vaultName, archiveId, new File(downloadFilePath)); long endTime = System.currentTimeMillis(); System.out.println("Elapsed Time = " + (endTime - startTime)); }catch(Exception e){ e.printStackTrace(); } } }
なぜかエラーがでてうまくいかない。regionがtokyoなのが問題?追加の設定がいるのかも。
Low Level APIでファイルのダウンロードをしてみる
High Levelでうまくいかなかったので、Low Levelでやってみた。まずはJobのリクエスト。
package myaws.glaceir; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.services.glacier.AmazonGlacierClient; import com.amazonaws.services.glacier.model.InitiateJobRequest; import com.amazonaws.services.glacier.model.InitiateJobResult; import com.amazonaws.services.glacier.model.JobParameters; public class TestJobDownload { public static String vaultName = "xxxx"; public static String archiveId = "xxxx"; public static AmazonGlacierClient client; public static void main(String args[]) throws Exception{ JobParameters params = new JobParameters(); params.withArchiveId(archiveId); params.withDescription("archive retrieval"); params.withType("archive-retrieval"); AWSCredentials credentials = new PropertiesCredentials (TestDownloadOperation.class.getResourceAsStream("AwsCredentials.properties")); client = new AmazonGlacierClient(credentials); client.setEndpoint("https://glacier.ap-northeast-1.amazonaws.com"); InitiateJobRequest request = new InitiateJobRequest(); request.withJobParameters(params); request.withVaultName(vaultName); InitiateJobResult result = client.initiateJob(request); String jobId = result.getJobId(); System.out.println("jobID = " + jobId); } }
3〜4時間まってみる。