# Backup a Single Channel?

**URL:** <https://forum.mattermost.com/t/backup-a-single-channel/10034>\
**Category:** Troubleshooting\
**Created:** [June 30, 2020, 8:59pm UTC](https://forum.mattermost.com/t/backup-a-single-channel/10034 "2020-06-30T20:59:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelGardiner](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@MichaelGardiner](https://forum.mattermost.com/u/MichaelGardiner)\
**Post date:** [June 30, 2020, 8:59pm UTC](https://forum.mattermost.com/t/backup-a-single-channel/10034/1 "2020-06-30T20:59:30Z")

</div>

Hi there,

My organization is planning on wiping Mattermost messages after _n_ months, but we have a **Contracts** channel that we would like to keep backed up indefinitely. Does anyone have a suggestion on how to organize something like that? Will I need to manually export from the DB every _n_ months?

Thank you very much and I appreciate the help.

---

<div class="post-metadata">

**Author:** ![ctlaltdieliet](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ctlaltdieliet/32/3986_2.png) [@ctlaltdieliet](https://forum.mattermost.com/u/ctlaltdieliet)\
**Post date:** [July 1, 2020, 6:28am UTC](https://forum.mattermost.com/t/backup-a-single-channel/10034/2 "2020-07-01T06:28:00Z")

</div>

Hi Michael,  
Maybe you could write a bot for that.

It would get all posts since the previous backup with [Get Posts](https://api.mattermost.com/#tag/posts/paths/~1channels~1%7Bchannel_id%7D~1posts/get).  
You get a list with all the posts, you can read each post with [Get Post](https://api.mattermost.com/#tag/posts/paths/~1posts~1%7Bpost_id%7D/get) If there are files included you can get them with Get File.

Your bot can store it in the way you want.  
Kind regards,  
Tom

---

<div class="post-metadata">

**Author:** ![MichaelGardiner](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@MichaelGardiner](https://forum.mattermost.com/u/MichaelGardiner)\
**Post date:** [July 1, 2020, 4:06pm UTC](https://forum.mattermost.com/t/backup-a-single-channel/10034/3 "2020-07-01T16:06:59Z")

</div>

Thank you Tom, I appreciate your response. I will look into this and report back!

---

<div class="post-metadata">

**Author:** ![ctlaltdieliet](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ctlaltdieliet/32/3986_2.png) [@ctlaltdieliet](https://forum.mattermost.com/u/ctlaltdieliet)\
**Post date:** [July 1, 2020, 7:21pm UTC](https://forum.mattermost.com/t/backup-a-single-channel/10034/4 "2020-07-01T19:21:25Z")

</div>

You could store all the posts in an single large HTM-file with some css. It could even look like the Mattermost channel and it is easy to store, copy and restore/search.

---

<div class="post-metadata">

**Author:** ![ahmaddanial](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/ahmaddanial/32/2938_2.png) [@ahmaddanial](https://forum.mattermost.com/u/ahmaddanial)\
**Post date:** [November 6, 2020, 2:21pm UTC](https://forum.mattermost.com/t/backup-a-single-channel/10034/5 "2020-11-06T14:21:23Z")

</div>

Hi, everyone.

I created this forum topic for your reference - [How to Export a Single Channel from Mattermost Server](https://forum.mattermost.com/t/how-to-export-a-single-channel-from-mattermost-server/10699) Hope it helps!

---

<div class="post-metadata">

**Author:** ![XxLilBoPeepsxX](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/xxlilbopeepsxx/32/4993_2.png) [@XxLilBoPeepsxX](https://forum.mattermost.com/u/XxLilBoPeepsxX)\
**Post date:** [November 8, 2020, 12:53am UTC](https://forum.mattermost.com/t/backup-a-single-channel/10034/6 "2020-11-08T00:53:31Z")

</div>

I would suggest writing some sort of a script, such as a bash file for Linux operating systems, that would automatically query the database and utilize the `DROP` command in combination with `IF` and regex strings, to allow you to match and automatically update the range of time that you want to delete messages in. You could also implement the `NOT` function into the query, for the channel ID of the channel you wish to preserve all messages in. If you were to schedule the script to be executed with a cron job then it is very possible that this could be a solution. You could additionally extend the functionality of the script by adding additional clauses to back up the specific channel(s) you wish to save to a SQL file, and commit them to a private GitHub repository or AWS S3 bucket prior to the deletion of other messages, etc.
