Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Created September 4, 2014 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyaevseev/81db6254d906dd4df4b0 to your computer and use it in GitHub Desktop.
Save ilyaevseev/81db6254d906dd4df4b0 to your computer and use it in GitHub Desktop.
Backup changed data to remote Mercurial repositories -- /etc/cron.daily/push2mercurial skeleton.
#!/bin/sh
WEBAPP_BASEDIR="/home/webapp"
HGSERVER_URI="http://webserv1:VerySecretPassword@mercurial.example.ru:5000"
Push0() {
local o="/tmp/$2.log"
local e="/tmp/$2.err"
(
cd "$1"
hg status | grep -q '' || return
#echo "$1 updated"
hg addremove
hg commit -m "Periodic autocommit $(LANG=C date +%Y.%m.%d_%H:%M:%S)"
hg push "$HGSERVER_URI/$2"
) >"$o" 2>"$e"
test -s "$e" || { rm "$e"; return; }
cat $o $e | mail -s "push2mercurial: $1 to $2 failed." admins
}
Push() { Push "$WEBAPP_BASEDIR/$1" "$2"; }
Push avatars webapp-avatars
Push uploads webapp-uploads
Push0 /etc webserv1-etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment