Delete old archived channels

Problem

A customer wants to permanently delete old archived channels

Solution

1. Make a backup!
2. make sure to Enable API channel deletion
3. You can run the following query to list all the channels that have been archived for more than a year:

PostgreSQL

-- 31556952000 is one year in milliseconds.
SELECT
teams.name || ':' || channels.name AS mmctlname
FROM channels
INNER JOIN teams ON teams.id = channels.teamid
WHERE channels.deleteat < (EXTRACT(EPOCH FROM now()) * 1000 - (31556952000))
AND channels.deleteat <> 0
AND channels.type IN ('O', 'P');

MySQL:

SELECT
CONCAT(Teams.name, ':', Channels.name) as mmctlname
FROM Channels
INNER JOIN Teams ON Teams.id = Channels.teamid
WHERE Channels.deleteat < (ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000) - (31556952000))
AND Channels.deleteat <> 0
AND Channels.type IN ('O', 'P');

4. The above query will return a list of the channels archived for more than one year, in a format "teamname:channelname". This format can then be used to run a mmctl command: https://docs.mattermost.com/manage/mmctl-command-line-tool.html#mmctl-channel-delete

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.