2022-02-11 21:47:18 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#
|
2022-02-11 23:32:18 +00:00
|
|
|
# Loads an SVN snapshot into a new repository.
|
2022-02-11 21:47:18 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-02-11 23:32:18 +00:00
|
|
|
if [[ ! -f "$backup_path" ]]; then
|
2022-02-11 21:47:18 +00:00
|
|
|
error "Backup file '$backup_path' doesn't exist.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-02-11 23:32:18 +00:00
|
|
|
if [[ ! -d "$repo_path" ]]; then
|
2022-02-11 21:47:18 +00:00
|
|
|
error "SVN repo '$repo_path' doesn't exist.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "${BOLD}${YELLOW}Loading backup '$backup_path' to '$repo_path'\n"
|
2022-02-11 23:32:18 +00:00
|
|
|
printf "The destination repo should be a new repo with no commits.\n"
|
2022-02-11 21:47:18 +00:00
|
|
|
printf "Proceed? (1|y)\n> ${NORMAL}"
|
2022-02-11 23:32:18 +00:00
|
|
|
|
2022-02-11 21:47:18 +00:00
|
|
|
read -e proceed
|
|
|
|
if [[ ! ($proceed == "1" || $proceed == "y") ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-02-11 23:32:18 +00:00
|
|
|
# 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"
|