Skip to content

Instantly share code, notes, and snippets.

@JonathonReinhart
Created February 18, 2018 22:38
Show Gist options
  • Save JonathonReinhart/84398cf8532ae3902f83119922ed4e69 to your computer and use it in GitHub Desktop.
Save JonathonReinhart/84398cf8532ae3902f83119922ed4e69 to your computer and use it in GitHub Desktop.
Rename SVN repository
#!/bin/bash
if [[ $# -lt 2 ]]; then
echo "Usage: `basename $0` oldrepo newrepo"
exit 1
fi
# http://stackoverflow.com/q/1848415/
OLDREPO=${1%/}
NEWREPO=$2
TEMP_DUMP=`mktemp`
# See if new repo filename already exists
if [[ -e $NEWREPO ]]; then
echo "$NEWREPO already exists!"
exit 3
fi
# Dump the old repo to temp file
echo ""
echo "Dumping old repository..."
echo ""
svnadmin dump $OLDREPO > $TEMP_DUMP
if [[ $? -ne 0 ]]; then
echo "Failed to dump old repository."
exit 2
fi
# Create the new repo
svnadmin create $NEWREPO
if [[ $? -ne 0 ]]; then
echo "Failed to create new repository."
exit 2
fi
# Change ownership of new repo to match that of old
USR_GRP=`stat -c %U:%G $OLDREPO`
chown -hR $USR_GRP $NEWREPO
if [[ $? -ne 0 ]]; then
echo "Could not change ownership of new repository."
exit 2
fi
# Load dump into new repo
echo ""
echo "Importing old repository..."
echo ""
svnadmin load $NEWREPO < $TEMP_DUMP
if [[ $? -ne 0 ]]; then
echo "Failed to load dump into repository."
exit 2
fi
# Cleanup
#mv $OLDREPO $OLDREPO.bak
echo ""
echo "Deleting old repository..."
echo ""
rm -rf $OLDREPO
rm $TEMP_DUMP
echo ""
echo "Success!"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment