Skip to content

Instantly share code, notes, and snippets.

@yakatz
Last active September 25, 2024 01:41
Show Gist options
  • Save yakatz/61e951c2144a733b376767cddc067310 to your computer and use it in GitHub Desktop.
Save yakatz/61e951c2144a733b376767cddc067310 to your computer and use it in GitHub Desktop.
Slack Auto-Backup Script
#! /bin/bash
cd "$(dirname "$0")"
logger="logger --stderr --id=$$ --tag slack-archive"
metadata_filename="metadata.json"
$logger "Start Backup: $(pwd)"
if [[ ! -s $metadata_filename ]]; then
$logger --priority user.err "${metadata_filename} missing $(pwd)"
exit 1
fi
if [[ ! -s slack-archive/.token ]] && [[ -z "${SLACK_TOKEN}" ]]; then
$logger --priority user.err "Slack OAuth Token missing $(pwd)"
exit 2
fi
archive_args=$( jq .arguements $metadata_filename )
$logger "CMD: $(pwd): /usr/bin/npx slack-archive ${archive_args//\"/""}"
/usr/bin/npx slack-archive ${archive_args//\"/""}
$logger "Archive Done, Committing to Git: $(pwd)"
git add -A
GIT_AUTHOR_NAME="slack-archive autocommit" GIT_AUTHOR_EMAIL="[email protected]" git commit -m "autocommit by slack-archive on $(hostname)"
git push
$logger "Git Commit Done: $(pwd)"
node_modules/
slack-archive/.token
slack-archive/data_backup_*
{
"arguements": "--channel-types public_channel --automatic"
}
{
"dependencies": {
"slack-archive": "^1.6.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment