0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

lxdコンテナをイメージファイル化して、そのままS3バケットへアップロードするスクリプト

Last updated at Posted at 2019-12-02

環境

Ubuntu 18.04 LTS

前提条件

  • LXDが利用できる
  • awscliがインストールされている
  • aws configureが完了している
  • IAMロール または IAMユーザーの認証情報が設定済み

実行方法

スクリプトのファイル名が、lxd_publish_image_to_s3.shの場合

# ./lxd_publish_image_to_s3.sh <LXDコンテナ名>

コード

IMAGE_OUTPUT_DIRに、lxdコンテナイメージファイルのアップロード先ディレクトリを指定
S3_BUCKETに、アップロード先のS3バケットを指定

#!/bin/sh
set -eu
IMAGE_NAME=${1}
IMAGE_OUTPUT_DIR=/data/lxd_images
S3_BUCKET=lxd-images
lxc publish ${IMAGE_NAME} --alias ${IMAGE_NAME}
lxc image export ${IMAGE_NAME} ${IMAGE_OUTPUT_DIR}/
mv `lxc image info ${IMAGE_NAME} | grep "Fingerprint:" | sed "s/Fingerprint: //g"`.tar.gz ${IMAGE_NAME}.tar.gz
aws s3 cp ${IMAGE_OUTPUT_DIR}/${IMAGE_NAME}.tar.gz s3://${S3_BUCKET}/
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?