---
title: "Google Cloud StorageでLifecycle！ | grasys blog"
url: "https://blog.grasys.io/post/yusukeh/google-cloud-storage-lifecycle"
description: "Website Logging設定したあとにLifecycleで古いファイルを消したりできる！ 便利だし簡単！ Object Lifecycle Management To support common use cases like setting a Time to Live (TTL) for objects or deleting older versions of objects, Google… cloud.google.co…"
---

# Google Cloud StorageでLifecycle！

-   ![](/_astro/noicon.CTHOhNiB_1HMs6A.webp)[yusukeh](/authors/yusukeh/)
-   公開日：2015年3月30日
-   カテゴリー：[Tech](/categories/tech/)
-   タグ：[#Google Cloud](/tags/google-cloud/)[#Cloud Storage](/tags/cloud-storage/)

![Google Cloud StorageでLifecycle！](/_astro/ogp.BgYHrv_v_ZwDwpK.webp)

Website Logging設定したあとにLifecycleで古いファイルを消したりできる！

便利だし簡単！

## Object Lifecycle Management

### To support common use cases like setting a Time to Live (TTL) for objects or deleting older versions of objects, Google…

cloud.google.com

## lifecycle\_config.json

こんなファイルを作って

Plain textcontent\_copy

```
{
    "rule":
    [
      {
        "action": {"type": "Delete"},
        "condition": {"age": 365}
      }
    ]
}
```

gsutilで設定

Plain textcontent\_copy

```
gsutil lifecycle set lifecycle_config.json gs://logs_xxx_xxxx_xxx
```

設定確認

Plain textcontent\_copy

```
gsutil lifecycle get gs://logs_xxx_xxxx_xxx
```

するとファイルが消されて行きます。

## 検証してみる

ちょっとわかりにくいかもしれないけど  
以下は検証目的で1日で削除するように設定した例

Plain textcontent\_copy

```
{
    "rule":
    [
      {
        "action": {"type": "Delete"},
        "condition": {"age": 1}
      }
    ]
}
```

4日間程度放置してみたけどファイルは1日分を残して消されてます。

あと重要なのはGoogle Cloud Storage Nearlineでも使えること！

転載：[Google Cloud StorageでLifecycle！](https://medium.com/@yusuke_h/google-cloud-storage%E3%81%A7lifecycle-2bda1d1ae736)

この記事は [Medium（@yusuke\_h）](https://medium.com/@yusuke_h) からの転載です。

## この記事を書いた人

[![](/_astro/yusukeh.BvUd2yKE_1mQ6Fp.webp)](/authors/yusukeh/)

### [yusukeh](/authors/yusukeh/)

Fly high. Think deep. Move fast. Go far.🦅

-   [X](https://x.com/yusukeh "X")
-   [GitHub](https://github.com/yusukeh "GitHub")
-   [Medium](https://medium.com/@yusukeh "Medium")
-   [Facebook](https://www.facebook.com/yusuke.exzm "Facebook")
-   [Instagram](https://www.instagram.com/yusukehasegawa/ "Instagram")
-   [LinkedIn](https://www.linkedin.com/in/hasegawa-yusuke-091b4164/ "LinkedIn")

[プロフィールと記事一覧](/authors/yusukeh/)