#!/bin/bash # author: Stefan Klinger # Database & Information Systems (DBIS) Group # Uni Konstanz # license: GNU Affero General Public License # file LICENSE, or # # Subversion information: # $HeadURL$ # $Date$ set -u -e -C; shopt -s failglob; function err { echo "$@" >&2; exit 1; } function warn { echo "$@" >&2; } function ask_yN { local answer=''; read -n 1 -s -p "$* [yN]" answer; if test "${answer}" = y; then echo yes; return 0; fi; echo no; return 1; } # This is the home of the repository home='/home/svn/dbis'; # The name of the repos name="${1:?need repository name}"; # Assert this repos exists. test -d "${home}/repos/${name}" || err "No such repos"; # Assert the backup directory is there test -d "${home}/old-repos" || err "No directory for old repositories"; # Check for existing backups with same name find "${home}/old-repos" -path "${home}/old-repos/${name}*" | grep -F "/${name}" && err 'collision with existing backup?'; # Ask the user: Sure? cat < "${home}/old-repos/${name}.access"; chmod 440 "${home}/old-repos/${name}.access"; else warn "No old access file. Not backed up."; fi; tee "access.d/${name}" < "${name}.tar.bz2"; rm -rf "${name}"; chmod 440 "${name}.tar.bz2"; # Do a dump of entire repos, and compress into `${name}.dump.bz2` cat < "${name}.dump.bz2"; chmod 440 "${name}.dump.bz2"; # Do a plain file system level copy of the repos, and compress into # `${name}.repos.tar.bz2`. The trick with the symlink is required to # create a tar archive whose only member is named like the archive. cat < "${name}.repos.tar.bz2"; rm "${name}.repos"; chmod 440 "${name}.repos.tar.bz2"; # “Remove” repos. Lacking sufficient permissions, we simply move it # to the `DELETE_ME` subdir. Occasionally, some Admin has todelete # that. cat <