Skip to content

Instantly share code, notes, and snippets.

@martinseener
Created Jun 25, 2014
Embed
What would you like to do?
RORK (Redmine Orphaned Repositories Killer)
#!/usr/bin/env bash
# Rork v.0.1 (Redmine Orphaned Repositories Killer)
# (c) 2014 Martin Seener (martin@seener.de)
# Deletes orphaned Redmine Repositories which cannot be deleted from within Redmine
# Usage: You only need the original path to the repository. The rest will be handled by this tool.
# Attention: This tool must be run from the "postgres" user, because it does not handle authentication yet.
# How does it work?
# 1. It gets the repository id using a search for the repository path
# 2. It deletes all entries from the "changes" table
# 3. It deleted all entries from the "changesets" table
# 4. ... and finally deletes the entry from the "repositories" table
if [ "$1" == '' ]; then
echo -e "\e[0;31mAborting. There is no database name given. Usage: rork.sh <dbname> <pathToRepo>"
exit 1
fi
if [ "$2" == '' ]; then
echo -e "\e[0;31mAborting. There is no repository path given. Usage: rork.sh <dbname> <pathToRepo>"
exit 1
fi
echo -e "\e[0;32mDeleting all entries of 'changes' table from repository '$2' in the database '$1'\e[00m"
psql -d $1 -c "DELETE FROM changes WHERE changes.changeset_id IN (SELECT changesets.id FROM changesets WHERE changesets.repository_id IN (SELECT id FROM repositories WHERE root_url = '$2'));"
echo -e "\e[0;32mDeleting all entries of 'changesets' table from repository '$2' in the database '$1'\e[00m"
psql -d $1 -c "DELETE FROM changesets WHERE changesets.repository_id IN (SELECT id FROM repositories WHERE root_url = '$2');"
echo -e "\e[0;32mDeleting repository '$2' from 'repositories' table in the database '$1'\e[00m"
psql -d $1 -c "DELETE FROM repositories WHERE root_url = '$2';"
echo -e "\e[0;32mDone!\e[00m"
exit 0
@martinseener
Copy link
Author

martinseener commented Jun 25, 2014

Be aware, this little script has no real or good checks for what you input. Use with caution and make a backup first! This tool is also tested with Redmine v2.5.1 and PostgreSQL 9.1.12 but should work great with older or later versions. Licensed under the GPL-v2.

I appreciate any enhancements!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment