Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting Chat Room Logs +30 day crontab #7228

Closed
waveyuk opened this issue Jun 12, 2017 · 15 comments · Fixed by #11236
Closed

Deleting Chat Room Logs +30 day crontab #7228

waveyuk opened this issue Jun 12, 2017 · 15 comments · Fixed by #11236

Comments

@waveyuk
Copy link

waveyuk commented Jun 12, 2017

I've looked to see if anyone has come up with a solution for this.
I would like to be able to run a crontab job which deletes any messages from any room which are older than 30 days. Is this at all possible? My concern is that the Mongo database will quickly fill with messages and cause the server to run out of disk space on active channels. I've seen posts about using the API but it isn't clearly explained how to achieve this. Our Rocket Chat is running in a Snap environment.
Thanks

Rocket.Chat Version: 0.56.0
Running Instances: 1
DB Replicaset OpLog: Enabled
Node Version: 4.8.1

@graywolf336
Copy link
Contributor

You could possibly use this api: https://rocket.chat/docs/developer-guides/rest-api/channels/cleanhistory

@waveyuk
Copy link
Author

waveyuk commented Jun 12, 2017

@graywolf336 that was the API I was referencing in the post. However, what is not clear is on the parameters. For example, where do you get the X-Auth-Token from (or how do you generate it). I assume the X-User-Id would be the system admin ID, but again, how do you find that out?

@graywolf336
Copy link
Contributor

@waveyuk Take a look at how to authenticate: https://rocket.chat/docs/developer-guides/rest-api/authentication

@waveyuk
Copy link
Author

waveyuk commented Jun 12, 2017

@graywolf336 ok- seen that... unfortunately, I am not a whizz with linux and curl, so don't know how to build a script that could pass the authentication results into the command line to accomplish this. If anyone can help, would appreciate it.

@mostlycoolmark
Copy link

Here's a sample script to get you started. You probably want to iterate through ALL rooms, though, right?
rocketchat_delete_old_messages.txt
@waveyuk

@waveyuk
Copy link
Author

waveyuk commented Jun 15, 2017

Hi @geesper
Thanks for that. You'll have to excuse me, as I am not very tech savvy when it comes to Linux (I am more of a Windows man!!).
Firstly... How would I run that script? What do I need to be aware of if I am running Rocket.Chat in a Snap environment?
Secondly, is there a way to iterate through ALL rooms, including Direct Messages, programatically? Obviously I could use your script to clean an individual room by specifying it, but not so easy for cleaning Direct Messages. Is this even possible?
Really appreciate your help @geesper
Dave

@mostlycoolmark
Copy link

mostlycoolmark commented Jun 16, 2017

powershell_remove_old_messages.txt
Unfortunately, it doesn't look like there's a way through the api to query for direct messages. It's doable directly in the database, but I'm not inclined to go down that route.

We can definitely get a list of the public rooms and then go through them all, though. I could spend a few minutes and put this into powershell, if that makes more sense to you than a shell script.

edit: I've added a powershell script that iterates through all channels and deletes messages older than X days. Please test this before using in production!

@mostlycoolmark
Copy link

Actually, looks like there may be a way to get a list of all direct messages? https://rocket.chat/docs/developer-guides/rest-api/im/list-everyone

I'll take a closer look at that.

@graywolf336
Copy link
Contributor

@geesper I meant to respond earlier and say there was, but it is disabled by default due to security and privacy purposes.

@waveyuk
Copy link
Author

waveyuk commented Jun 18, 2017

@geesper ... Thanks for the powershell script. I'll give that a go as soon as my internet connection returns to being stable (having issues with Virgin Media broadband at the moment).

@graywolf336 is there any way to get around the disabled function to delete direct messages? Obviously as server admin I would like to keep my server as clean as possible and dispose of old, out of date direct messages that consume database space but are no longer being used.

Thanks guys
Dave

@waveyuk
Copy link
Author

waveyuk commented Jun 19, 2017

@geesper
Is there a way to make the bin/bash script you created for me iterate through all the public chat rooms on the server? I've been doing some research and think I've found a way to run this. It would be better than running it via PowerShell as I wouldn't have to open up port 3000 on the firewall, as I could run it directly on the server as a cronjob.
Thanks for all your help
Dave

@mostlycoolmark
Copy link

rocketchat_delete_old_messages.txt

OK, here's an updated bash script that will iterate through all channels. Unfortunately, while the api allows you to grab a list of the direct message rooms, the api doesn't allow you to clean their history.

The script should be easy to update later if/when that functionality is added.

IMPORTANT NOTE: You will need to install jq on the linux machine you're running this from. This is used to parse the json response that the api gives back. Let me know if you run into any problems! Please be sure to run this on a test server before using it in production!

@graywolf336
Copy link
Contributor

@geesper if you really wanted to, you could get a list of the messages in a direct room and call chat.delete https://rocket.chat/docs/developer-guides/rest-api/chat/delete I know it's not the best, but it can make do right now 🤔

@mostlycoolmark
Copy link

Yeah, I don't really want to do that because of how inefficient it would be.

We'd have to:

Considering there may be thousands or tens of thousands of messages, that could take a long long time.

My hope is that the channels.cleanHistory allows DM's, or that maybe the ims api gets its own cleanHistory call.

@sampaiodiego sampaiodiego added this to the Long-term milestone Apr 3, 2018
ggazzo pushed a commit that referenced this issue Jul 20, 2018
Closes #6749
Closes #8321
Closes #9374
Closes #2700
Closes #2639
Closes #2355 
Closes #1861
Closes #8757
Closes #7228
Closes #10870
Closes #6193 
Closes #11299
Closes #11468
Closes #9317
Closes #11300 (will incorporate a fix to this PR's issue)
Closes #11046 (will incorporate a fix to this PR's issue)
Contributes to #5944 
Contributes to #11475
_...and possibly more!_

This PR makes deleting messages (automatically and manually) a lot easier on Rocket.Chat.

- [X] Implement a bulk message deletion notification, to quickly push large message deletions to users without reload
  - [X] Use it in `rooms.cleanHistory`
  - [X] Use it in user deletions
- [X] Completely remove cleanChannelHistory as required by v0.67
  - [X] Remove server method `cleanChannelHistory`
  - [X] Remove REST API `channels.cleanHistory`
- [x] Implement a sidebar option to clean history
  - [x] Basic implementation
  - [x] Allow excluding pinned messages
  - [x] Allow attachment-only mode
  - [x] Allow specifying user(s) to narrow down to
    - [x] Also update REST API
    - [x] Also update docs
  - [x] Break the deletion into multiple different requests, so the client can keep track of progress
  - [x] Clear animation / progress bar for deleting
- [x] Retention policy
  - [X] Global, set by admin
    - [X] Global timer that runs every second and deletes messages over the set limit
      - [X] Can change its timer's resolution to prevent insane CPU overhead
    - [X] Admin can decide what room types to target (channels, groups and/or DMs)
    - [X] Allow excluding pinned messages
    - [X] Allow attachment-only mode
  - [x] Per-channel, set by those with a new permission
    - [x] Disabled when master switch off
    - [x] Set in channel info
    - [x] Can override global policy with a switch that requires `edit-privileged-setting`
    - [x] Allow excluding pinned messages
    - [x] Allow attachment-only mode
    - [x] Uses same global timer for cleanup
  - [X] Message at start of channel history / in channel info if there is a retention policy set
  - [x] Message in channel info if there is a retention policy set on that channel specifically
- [X] Make cleaning history also delete files (completely!)
  - [X] Manual purging
  - [X] Automatic purging
- [x] Make other deletions also delete files
  - [x] User deletion
    - [X] Own messages
    - [x] DMs with them's partner messages
  - [x] Room deletion
- [x] Cleanup
- [x] Finish related [docs](https://github.com/RocketChat/docs/pull/815)
- [x] Link to the docs in the settings

Please suggest any cool changes/additions! Any support is greatly appreciated.

**Breaking change:** This PR removes REST API endpoint `channels.cleanHistory` and Meteor callable `cleanChannelHistory` as per the protocol specified for them.

![bzzzzzzzz](https://user-images.githubusercontent.com/39674991/41799087-56d1dea0-7670-11e8-94c0-bc534b1f832d.png)
@mnlbox
Copy link

mnlbox commented Sep 12, 2018

Guys any news about this?

@theorenck theorenck removed this from the Long-term milestone Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants