# Snapshot Lifecycle Management (SLM) in Python 3

**URL:** <https://discuss.elastic.co/t/snapshot-lifecycle-management-slm-in-python-3/286208>\
**Category:** Elasticsearch\
**Tags:** slm-snapshot-lifecycle-management\
**Created:** [October 8, 2021, 8:57am UTC](https://discuss.elastic.co/t/snapshot-lifecycle-management-slm-in-python-3/286208 "2021-10-08T08:57:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ttttien](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@ttttien](https://discuss.elastic.co/u/ttttien)\
**Post date:** [October 8, 2021, 8:57am UTC](https://discuss.elastic.co/t/snapshot-lifecycle-management-slm-in-python-3/286208/1 "2021-10-08T08:57:28Z")

</div>

Hello,

I had done "snapshot" for the indexes in an database Elasticsearch by script :

es.snapshot.create(repository=repository\_name, snapshot=snapshot\_name)

I would like to Automatic backup with SML. I really need your help of my frend here to show me the step how to create an SML policy, and how to use, how to write the code. I have refered this link, but do not clear how to do ([https://www.elastic.co/.../getting-started-snapshot...](https://www.elastic.co/guide/en/elasticsearch/reference/7.10/getting-started-snapshot-lifecycle-management.html?fbclid=IwAR3p_xgZevKVWpZdGkEnSeuohrUtHe-WqS3AfLIrmPerZsbgSxw88jsZ7DU#slm-gs-register-repository))

I think I misunderstood how is "policy\_id" or there is the steps that I do not know before running the below code - The code I wrote to Automatic backup with SML:  
#################  
policy\_id= "container2" #(Required, string) ID for the snapshot lifecycle policy you want to create or update.

request\_body = { #(Required, object) Configuration for each snapshot created by the policy.

"schedule": "0 30 1 \* \* ?", # When the snapshot should be taken, in this case, 1:30am daily

"name": "\<container2-{now/d}\>", # The name each snapshot should be given

"repository": "Repo1", # Which repository to take the snapshot in

"config": { # Any extra snapshot configuration

```
"indices": ["container2"], #Data streams and indices the snapshot should contain (container2,container3)

"ignore_unavailable": False, 

"include_global_state": False #

```

},

"retention": { #Optional retention configuration

```
"expire_after": "30d", # Keep snapshots for 30 days

"min_count": 5, # Always keep at least 5 successful snapshots, even if they’re more than 30 days old

"max_count": 50 # Keep no more than 50 successful snapshots, even if they’re less than 30 days old ( <200)

```

}  
}

es.slm.put\_lifecycle(policy\_id = policy\_id, body = request\_body)

#############  
The error I obtained is in the picture

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/4/745abafa6e6710548d6258e5f85371a4cdd3b49d.png)

Thanks very much in advance for your help

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 5, 2021, 8:57am UTC](https://discuss.elastic.co/t/snapshot-lifecycle-management-slm-in-python-3/286208/2 "2021-11-05T08:57:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
