74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
#
 | 
						|
# Loads an SVN snapshot into a new repository.
 | 
						|
#
 | 
						|
 | 
						|
if which tput >/dev/null 2>&1; then
 | 
						|
    ncolors=$(tput colors)
 | 
						|
fi
 | 
						|
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
 | 
						|
    RED="$(tput setaf 1)"
 | 
						|
    GREEN="$(tput setaf 2)"
 | 
						|
    YELLOW="$(tput setaf 3)"
 | 
						|
    BLUE="$(tput setaf 4)"
 | 
						|
    MAGENTA="$(tput setaf 5)"
 | 
						|
    CYAN="$(tput setaf 6)"
 | 
						|
    BOLD="$(tput bold)"
 | 
						|
    NORMAL="$(tput sgr0)"
 | 
						|
else
 | 
						|
    RED=""
 | 
						|
    GREEN=""
 | 
						|
    YELLOW=""
 | 
						|
    BLUE=""
 | 
						|
    MAGENTA=""
 | 
						|
    CYAN=""
 | 
						|
    BOLD=""
 | 
						|
    NORMAL=""
 | 
						|
fi
 | 
						|
 | 
						|
error() {
 | 
						|
    printf "${BOLD}${RED}$1${NORMAL}\n"
 | 
						|
}
 | 
						|
 | 
						|
set -e
 | 
						|
 | 
						|
backup_path="$1"
 | 
						|
repo_path="$2"
 | 
						|
 | 
						|
if [[ ($backup_path == "") || ($repo_path == "") ]]; then
 | 
						|
    error "Missing args: <backup file path> <svn repo path>"
 | 
						|
    exit 1
 | 
						|
fi
 | 
						|
 | 
						|
if [[ ! -f "$backup_path" ]]; then
 | 
						|
    error "Backup file '$backup_path' doesn't exist.\n"
 | 
						|
    exit 1
 | 
						|
fi
 | 
						|
 | 
						|
if [[ ! -d "$repo_path" ]]; then
 | 
						|
    error "SVN repo '$repo_path' doesn't exist.\n"
 | 
						|
    exit 1
 | 
						|
fi
 | 
						|
 | 
						|
printf "${BOLD}${YELLOW}Loading backup '$backup_path' to '$repo_path'\n"
 | 
						|
printf "The destination repo should be a new repo with no commits.\n"
 | 
						|
printf "Proceed? (1|y)\n> ${NORMAL}"
 | 
						|
 | 
						|
read -e proceed
 | 
						|
if [[ ! ($proceed == "1" || $proceed == "y") ]]; then
 | 
						|
    exit 1
 | 
						|
fi
 | 
						|
 | 
						|
# Was having trouble getting this to work on svnadmin 1.14.1 on Windows:
 | 
						|
#   gunzip -c "$backup_path" | svnadmin load "$repo_path"
 | 
						|
# It was very slow and the output would freeze.
 | 
						|
# So now we unzip and then import.
 | 
						|
source_dir=$(dirname "$backup_path")
 | 
						|
dump_file="$source_dir/$RANDOM.dump"
 | 
						|
printf "${BOLD}Unzipping to '$dump_file'\n"
 | 
						|
gunzip -cf "$backup_path" >> "$dump_file"
 | 
						|
printf "${BOLD}Loading into SVN repo\n"
 | 
						|
svnadmin load -F "$dump_file" "$repo_path"
 | 
						|
rm "$dump_file"
 |