1
Fork 0
recovering-deleted-wagtail-.../slides.md

162 lines
2.3 KiB
Markdown
Raw Normal View History

2024-04-05 18:01:50 +01:00
---
title: Recovering deleted Wagtail pages and Django models
class: text-center
highlighter: shiki
transition: slide-left
2024-04-18 17:05:39 +01:00
mdc: true
themeConfig:
primary: '#fd5765'
2024-04-05 18:01:50 +01:00
---
2024-04-18 17:05:39 +01:00
# Recovering [deleted]{style="color: #fd5765"} Wagtail pages and Django models
2024-04-05 18:01:50 +01:00
2024-04-18 17:05:39 +01:00
### Jake Howard{style="color: #e85537;" }
2024-04-05 18:01:50 +01:00
2024-04-18 17:05:39 +01:00
<ul class="list-none! text-sm [&>li]:m-0! mt-1 uppercase font-light">
<li><em>Senior Systems Engineer</em> @ Torchbox</li>
<li><em>Security Team</em> & <em>Performance Working Group</em> @ Wagtail</li>
</ul>
<ul class="list-none! text-sm [&>li]:m-0! mt-3">
<li><mdi-earth /> theorangeone.net</li>
<li><mdi-twitter /> @RealOrangeOne</li>
<li><mdi-github /> @RealOrangeOne</li>
<li><mdi-mastodon /> @jake@theorangeone.net</li>
</ul>
2024-04-05 18:01:50 +01:00
---
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
---
<style>
pre.shiki {
font-size: 1.4rem;
}
</style>
# 2. Locate the page models
<div class="pt-5">
```python
from wagtail.models import Page
sysadmin_page = Page.objects.get(id=91)
child_pages = sysadmin_page.get_descendants()
```
</div>
---
layout: center
---
<style>
pre.shiki {
font-size: 1.4rem;
}
</style>
# 3. Locate what was deleted
<div class="pt-5">
```python
from django.contrib.admin.utils import NestedObjects
collector = NestedObjects()
collector.collect(list(child_pages) + [sysadmin_page])
```
</div>
---
layout: center
---
<style>
pre.shiki {
font-size: 1.4rem;
}
</style>
# 4. Serialize
<div class="pt-5">
```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
)
```
</div>
---
layout: center
---
# 4a. Deserialize
---
layout: center
---
# 5. Test test test
---
layout: center
---
# 6. Showtime!
---
layout: end
---
# Conclusion