---
title: Recovering deleted Wagtail pages and Django models
class: text-center
highlighter: shiki
transition: slide-left
---
# Recovering deleted Wagtail pages and Django models
### Jake Howard
###### Senior Systems Engineer @ Torchbox
###### Security Team @ Wagtail
###### Performance Working Group @ Wagtail
---
layout: cover
background: https://cdn.jsdelivr.net/gh/wagtail/wagtail@main/.github/wagtail-screenshot-with-browser.png
---
# Setting the scene
---
layout: cover
---
# Site history report
---
layout: cover
---
# Restoring from backups
---
layout: cover
---
# _Partial_ restores from backups
---
layout: center
---
# 1. Spin up a database backup
---
layout: center
---
# 2. Locate the page models
```python
from wagtail.models import Page
sysadmin_page = Page.objects.get(id=91)
child_pages = sysadmin_page.get_descendants()
```
---
layout: center
---
# 3. Locate what was deleted
```python
from django.contrib.admin.utils import NestedObjects
collector = NestedObjects()
collector.collect(list(child_pages) + [sysadmin_page])
```
---
layout: center
---
# 4. Serialize
```python
from django.core import serializers
class NoM2MSerializer(Serializer):
def handle_m2m_field(self, obj, field):
pass
def get_model_instances():
for qs in collector.data.values():
yield from qs
with open("deleted-models.json", "w") as f:
NoM2MSerializer().serialize(
get_model_instances(),
stream=f
)
```
---
layout: center
---
# 4a. Deserialize
---
layout: center
---
# 5. Test test test
---
layout: center
---
# 6. Showtime!
---
layout: end
---
# Conclusion