# How to delete EVERYTHING from my forum and just leave the users?

**URL:** https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083
**Category:** Support
**Created:** [December 7, 2022, 2:25am UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083 "2022-12-07T02:25:27Z")
**Posts on this page:** 11
**Page:** 2

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [December 8, 2022, 2:17pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/21 "2022-12-08T14:17:14Z")

</div>

> [@xebiyen](#):
>
> but would they be invited?

That’s the fastest and easiest way, from far.  
Download your user list as @JammyDodger suggested, from `/admin/users/list/active`, download the CSV file, clean it up to keep only the email addresses, and do a bulk invite from your admin interface from a new Discourse installation. Your users will have to create an account again.

> [@xebiyen](#):
>
> I wanted to keep them the same, no invitations.

If you want to delete all data except some users, there is no easy way to do that and I can only think that trying could easily lead to a broken forum.

If you want to export most data of your users (their own settings and stuff), it will also be difficult and will require creating a ruby on rails script. Also, you could face issues that I didn’t think about. If you’re not sure how to do that, I’d suggest you stick to the first solution or post in #Marketplace if you have a budget.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 8, 2022, 2:58pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/22 "2022-12-08T14:58:23Z")

</div>

> [@Canapin](#):
>
> there is no easy way to do that and I can only think that trying could easily lead to a broken forum.

That’s true. But if you want to live dangerously, you can try this:

```plaintext
./launcher enter app
discourse backup
rails c
Topic.where("user_id > 1").destroy_all
Upload.where("user_id > 1").destroy_all
exit
exit

```

I think that deleting topics should delete posts, but you could also add a

```
 Post.where("user_id > 0").destroy_all

```

The `> 1` will leave topics created by the first user. If you want to delete those as well, change it to `> 0`,which will leave topics created by `@system`. I think you’ll be very sorry if you delete those.

That makes a backup in case it destroys everything.

This is almost certainly a bad idea, but it’s what you asked for.

---

<div class="post-metadata">

### Author: ![leonardo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leonardo/32/228634_2.png) [@leonardo](https://meta.discourse.org/u/leonardo)
#### Post date: [December 8, 2022, 5:29pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/23 "2022-12-08T17:29:48Z")

</div>

> [@pfaffman](#):
>
> This is almost certainly a bad idea

Indeed! There’s the `PostDestroyer` class for that, which does a lot of necessary extra cleanup.

@xebiyen you can use this rake task to destroy all topics across all categories, but leave categories and users intact:

```bash
$ ./bin/rake destroy:topics_all_categories

```

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [December 8, 2022, 10:42pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/24 "2022-12-08T22:42:05Z")

</div>

Awesome, I didn’t know this rake task. Will it remove the “About” topics, which would be an unwanted side effect?

---

<div class="post-metadata">

### Author: ![leonardo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leonardo/32/228634_2.png) [@leonardo](https://meta.discourse.org/u/leonardo)
#### Post date: [December 8, 2022, 10:50pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/25 "2022-12-08T22:50:20Z")

</div>

No, the method it uses leaves those alone by default, and the rake task does not change that default:

> <https://github.com/discourse/discourse/blob/16e3bc3ff4f5c0e9191d45985c4af956aee32c41/app/services/destroy_task.rb#L12>

🌈

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [December 8, 2022, 11:16pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/26 "2022-12-08T23:16:53Z")

</div>

Thank you for confirming this. I wanted to be sure, because one or two of the recommended methods for other things listed on [Administrative Bulk Operations](https://meta.discourse.org/t/administrative-bulk-operations/118349) had unwanted side effects the last time I used them.

I used one to move topics from one category to another but it moved the about topic along the regular topics. I might have used a rails script instead of the rake task though. I’m not sure. 🤔

I also used the “[move all topics with a specific tag to a single category](https://meta.discourse.org/t/administrative-bulk-operations/118349#move-all-topics-with-a-specific-tag-to-a-single-category-15)” rake method, which [didn’t populate properly some tags-related tables](https://meta.discourse.org/t/bulk-tagged-topics-then-moved-topics-into-another-category-but-the-category-tag-selector-doesnt-show-tags/213136) in the database.

* * *

edit: oh, it’s my Cake Day! If only [the cake was real](https://www.youtube.com/watch?v=Y6ljFaKRTrI)… But maybe it is though?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 9, 2022, 12:54am UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/27 "2022-12-09T00:54:03Z")

</div>

> [@leonardo](#):
>
> There’s the `PostDestroyer` class for that, which does a lot of necessary extra cleanup.

Thanks! I’d forgotten about that class and didn’t know about the rake task (or don’t remember forgetting it!)

---

<div class="post-metadata">

### Author: ![xebiyen](https://avatars.discourse-cdn.com/v4/letter/x/858c86/32.png) [@xebiyen](https://meta.discourse.org/u/xebiyen)
#### Post date: [December 9, 2022, 1:00pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/28 "2022-12-09T13:00:38Z")

</div>

what command do i use before this command?

---

<div class="post-metadata">

### Author: ![xebiyen](https://avatars.discourse-cdn.com/v4/letter/x/858c86/32.png) [@xebiyen](https://meta.discourse.org/u/xebiyen)
#### Post date: [December 9, 2022, 1:01pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/29 "2022-12-09T13:01:47Z")

</div>

@pfaffman @Canapin is his command @leonardo the best solution then?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [December 9, 2022, 1:52pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/30 "2022-12-09T13:52:24Z")

</div>

You can try by yourself, but do a backup first.  
Go to your discourse folder in command line.  
Enter the container with `./launcher enter app`.  
Then write `rake destroy:topics_all_categories`.

See it in action (my test instance is very slow):

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [January 8, 2023, 1:53pm UTC](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083/31 "2023-01-08T13:53:18Z")

</div>

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

[Previous page](https://meta.discourse.org/t/how-to-delete-everything-from-my-forum-and-just-leave-the-users/248083.md?page=1)
