dotfiles/bin/backup-svn-repo

60 lines
1.2 KiB
Bash

#!/usr/bin/env bash
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
repo_path="$1"
output_path="$2"
if [[ $repo_path == "" || $output_path == "" ]]; then
error "Missing args: <svn repo path> <output path>"
exit 1
fi
if [[ ! -d "$repo_path" ]]; then
error "Repo directory '$repo_path' doesn't exist."
exit 1
fi
output_path="$output_path/svn"
mkdir -p "$output_path"
now=$(echo $(date '+%Y-%m-%d-%H-%M-%S'))
backup_path="$output_path/${now}_jellypixel_repos.dump.gz"
printf "${BOLD}${YELLOW}Backing up '$repo_path' to '$backup_path'\n"
printf "Proceed? (1|y)\n> ${NORMAL}"
read -e proceed
if [[ ! ($proceed == "1" || $proceed == "y") ]]; then
exit 1
fi
svnadmin.exe dump "$repo_path" | gzip -9 > "$backup_path"