Created
June 29, 2015 10:02
-
-
Save ilyaevseev/6858efcbcd399b0d082e to your computer and use it in GitHub Desktop.
Backup all Git and Mercirial repos from Rhodecode/Kallithea to remote server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
M="admins" | |
L="/tmp/hg2mirror.log" | |
E="/tmp/hg2mirror.err" | |
TOPDIR="/var/www/rhodecode/" | |
try_mercurial() { | |
test -d "$1/.hg" || return 1 | |
cd "$1" | |
hg push -f "ssh://mirror/$(echo $1 | sed -e s,^$TOPDIR/,,)" | |
return 0 | |
} | |
try_git() { | |
local d f | |
for d in branches hooks info logs objects refs; do test -d "$1/$d" || return 1; done | |
for f in HEAD config description ; do test -f "$1/$f" || return 1; done | |
cd "$1" | |
# Prepare: git remote add mirror git-mirror:abbigli-site | |
# On remote: git init ... ; cd ... ; git config receive.denyCurrentBranch ignore | |
git push mirror master | |
return 0 | |
} | |
try_dir() { | |
try_mercurial "$1" && return 0 | |
try_git "$1" && return 0 | |
cd "$1" || return 1 | |
local d | |
for d in *; do | |
test "$d" = "*" && { echo "ERROR: $1/$d is empty, skipped."; return 1; } | |
test -d "$1/$d" || continue | |
try_dir "$1/$d" | |
done | |
} | |
cd "$TOPDIR/" || exit 1 #report? | |
for d in *; do | |
test -d "$TOPDIR/$d" || continue | |
test "$d" = "${d#rm__}" || continue | |
test "$d" = "data" && continue | |
try_dir "$TOPDIR/$d" | |
done > "$L" 2>"$E" | |
test -s "$E" || exit 0 | |
cat "$E" "$L" | mail -s "hg2mirror failed" $M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment