Created
June 25, 2014 15:25
-
-
Save martinseener/f25aaf5707689c9dc49b to your computer and use it in GitHub Desktop.
RORK (Redmine Orphaned Repositories Killer)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!