Skip to main content
https://travis-ci.org/gryf/slack-backup.svg?branch=master https://img.shields.io/pypi/v/slack-backup.svg

The project aim is to collect conversations from Slack using its API and optionally user account information, and provides convenient way to represent as a log.

Requirements

This project is written in Python 3, 3.4 to be precise (currently it works with version 3.6), although it may work on earlier version of Python3. Sorry no support for Python2.

Other than that, required packages are as follows:

  • slackclient 1.0.2

  • SQLAlchemy 1.0.10

Installation

You can install it using pip install slack-backup command. Recommended way is to create virtualenv, like so:

user@localhost $ virtualenv -p python3 myenv
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in foobar/bin/python3
Also creating executable in foobar/bin/python
Installing setuptools, pip, wheel...done.
user@localhost $ . myenv/bin/activate
(myenv)user@localhost $ pip install slack-backup

You can also get this repository and install from it, like:

user@localhost ~ $ virtualenv -p python3 myenv
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in foobar/bin/python3
Also creating executable in foobar/bin/python
Installing setuptools, pip, wheel...done.
user@localhost $ . myenv/bin/activate
(myenv)user@localhost ~ $ cd myenv
(myenv)user@localhost ~/myenv $ git clone https://github.com/gryf/slack-backup
(myenv)user@localhost ~/myenv $ cd slack-backup
(myenv)user@localhost ~/myenv/slack-backup $ pip install .

Usage

There is a commandline tool called slack-backup, which typical use would get to gather the data and generate logs. Using example from above, here is a typical session:

(myenv)user@localhost ~/myenv/slack-backup $ mkdir ~/mylogs && cd ~/mylogs
(myenv)user@localhost ~/mylogs $ slack-backup fetch \
--token xxxx-1111111111-222222222222-333333333333-r4nd0ms7uff \
--user some@email.address.org --password secret --team myteam \
-qq -d mydatabase.sqlite

where:

  • --token is generated on Slack side token for interaction with the API. It’s required.

  • --user is your slack account username…

  • --password …and password. Those two are needed if you care about files posted on the channels, which are hosted on Slack servers. They can be skipped, if you don’t care about such files. Avatars still be downloaded though. External resources will not be downloaded - they have URL anyway.

  • --team team name. It is the part of the URL for your slack team; in other words in URL like http://foobar.slack.com foobar is the team name.

  • -q (or --quiet) will suppress any messages from program. In contrary there can be used --verbose to increase verbosity. Using this option several times (up to three, above the number will have no effect) will amplify effectiveness of either be quite or be verbose behaviour.

  • -d or --database is the file path for database (which for now at least is an sqlite database file). It can be omitted - in-memory db would be created, but you’ll (obviously) lost all the records. Besides the db file, assets directory might be created for downloadable items.

You can also specify directory, where pure response JSONs from Slack API will be stored by using -r/--raw-dir or by providing it in config file in fetch section as raw_dir (note the underscore in config file contrary to the swith, which have hyphen between raw and dir). This might be useful for debugging purposes.

There is one more switch to take into consideration - -f/--url-file-to-attachment which influence the way how external file share would be treated. First of all, what is external file share from slack point of view, one could ask. Slack have some sort of integration with Google services, like Google Drive, which provide slack users to create or “upload” files from Google Drive. “Upload”, since no uploading actually takes place, and only URL is provided for such “uploads”. By default slack-backup will create a file which is prefixed manual_download_ which will contain URL and destination path to the file, where user should manual download file to. Example file contents:

http://foo.bar.com/some/file --> assets/files/83340cbe-fee2-4d2e-bdb1-cace9c82e6d4
http://foo.bar.com/some/other/file --> assets/files/8a4c873c-1864-4f1b-b515-bbef119f33a3
http://docs/google.com/some/gdoc/file --> assets/files/ec8752bc-0bf8-4743-a8bd-9756107ab386

By setting --url-file-to-attachment flag (or making an option url_file_to_attachment set to true in config file) such “uploads” would be internally converted into Slack “attachment”, which internally is an object to store external links, so there is no need for user interaction.

During DB creation, all available messages are stored in the database. On the next run, fetch would only take those records, which are older from currently oldest in DB. So that it will only fetch a subset of the overall of the messages. As for the channels and users - complete information will be downloaded every time fetch command would be used.

Next, to generate a log files:

(myenv)user@localhost ~/mylogs $ slack-backup generate \
-v -d mydatabase.sqlite --format text -o logs

where:

  • --format is the desired format of the logs. For now only text format of the logs is supported (IRC style format). Format none will produce nothing.

  • -o or --output is the destination directory, where logs and possible assets will land.

The rest of the options (-d and -v) have same meaning as in fetch command.

See help for the slack-backup command for complete list of options.

Configuration

For convenience, you can place all of needed options into configuration file (aka .ini), which all options (with their defaults) will look like:

[common]
channels =
database =
quiet = 0
verbose = 0

[generate]
output =
format = text
theme = plain

[fetch]
url_file_to_attachment = false
user =
password =
team =
token =
raw_dir =

Note, that you don’t have to put every option. To illustrate fetch example from above, here is a corresponding config file:

[common]
database = mydatabase.sqlite
quiet = 2

[fetch]
user = some@email.address.org
password = secret
team = myteam
token = xxxx-1111111111-222222222222-333333333333-r4nd0ms7uff

Note, that only [common] and [fetch] sections are provided, so it is enough to invoke slack-backup command as:

(myenv)user@localhost ~/mylogs $ slack-backup fetch

There are couple of places, where configuration file would be searched for, in particular order:

  • file provided via argument -i or --config

  • slack-backup.ini in current directory

  • $XDG_CONFIG_HOME/slack-backup.ini, where $XDG_CONFIG_HOME usually defaults to $HOME/.config

Details

During first run, database with provided name is generated. For ease of use sqlite database is used, although it is easy to switch the engine, since there is an ORM (SQLAlchemy) used.

Slack users, channels and messages are mapped to SQLAlchemy models, as well as other information, like:

  • user profiles

  • channel topic

  • channel purpose

  • message reactions

  • message attachments

  • and files

Channels and users are always synchronized in every run, so every modification to the user or channels are overwriting old data. During first run, all messages are retrieved for all/selected channels. Every other run will only fetch those messages, which are older then newest message in the database - so that we don’t loose any old messages, which might be automatically removed from Slack servers. The drawback of this behaviour is that all past messages which was altered in the meantime will not be updated.

License

This work is licensed on 3-clause BSD license. See LICENSE file for details.

Release files for slack-backup 0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slack-backup 0.8
File Size Uploaded
slack-backup-0.8.tar.gz 32.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slack-backup 0.8
File Interpreter ABI Platform
slack_backup-0.8-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 68.3 kB

Release files / slack-backup-0.8.tar.gz

Download URL slack-backup-0.8.tar.gz
Size 32.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8d6541a191f45a3e94130489cd49e5bb800f35f3380ba82d7f6a8c8ac50665e1
BLAKE2b-256 checksum
How to use checksums
b0cea0d450b77aa13ca858883e7e86cafcadfa9a24f399f76cddd6faf026adbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release files / slack_backup-0.8-py2.py3-none-any.whl

Download URL slack_backup-0.8-py2.py3-none-any.whl
Size 35.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fe7d2a1aa4bceea482b29772316e16f599d4d65ae11ab9f4de074457efae625f
BLAKE2b-256 checksum
How to use checksums
c8df2725527e501969d2d7f014c36cc3eea350e37e31fee303682e19c3f659db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.8 This release

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4

1 release file

0.3

2 release files

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page