Backing Up A Slack Workspace

I needed to backup Slack messages as the 10,000 free messsages limit was fast approaching. There are two ways to do this.

Export Via Slack

The first method uses the export feature in the Slack admin already provided. This was constraining as it only parses messages from public channels within the workspace you are involved in. In Slack, we have private channels, direct messages to other memebers and the public channels.

Export via Slack API

The second method available is via the Slack API. An API - short for Application Programming Interface - is a set of functions to permit interaction instructions between different software.

Thankfully, there is a readily available Python script to connect to the Slack API and extract those messages in private channels. The one I chose to use (because it had good documentation) is called Slack Export by Zach Snell.

Exporting All Messages Using Python & Slack API

To get started, you’ll need to have Python 3 running on Windows for this to work smoothly and obey some other requirements. To use Python, I suggest using Anaconda. Alternatively, you can download directly from Python.org

When using this Python script to connect to the Slack API, you’ll need an access token so that the API can can connect to your workspace. To generate your specific token, visit the custom integrations page on the Slack website. Scroll down towards the middle of that page and you’ll find what you need.

Next, I cloned the Python script to a folder on my computer using git clone and the git location of the directory from Github.

As per the script’s documentation you’ll need to grab some dependencies that the script uses, so run the following:

pip install slacker
pip install pick

I needed to run the following requirement to avoid an error associated with _curses, that I encountered:

pip install windows-curses

Finally, to grab your messages run

python slack_export.py --token your_access_token_you_generated_earlier

Now, you can go to the folder where your script is stored on your computer to see a dump of all the Slack messages in JSON format.

comments powered by Disqus