blob: c69eb6618a7c59caf33a84edb7a2558e3630a5b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#!/bin/sh
# backup to removable, offline media
. $HOME/.shenv
. $HOME/lib/tputfs.sh
set -e
# determine removable media available and if it's m3, sync annex content
if mount | grep -q "/media/${USER}/m3"; then
HDD=/media/${USER}/m3
status syncing annex content
# we sync both ma and m3 here so that ma knows everything that got
# put onto m3
git annex sync --content ma m3
elif mount | grep -q "/media/${USER}/bkupsd"; then
HDD=/media/${USER}/bkupsd
else
echo "coldbkup: removable media not mounted" >&2
exit 1
fi
DEST=${HDD}/git
mkdir -p $DEST
# function to backup a repo: first arg is ssh path to repo, second arg
# is where to put it
gitbk ()
{
local long=$1
local short=$(basename $long)
local dest=$2
if [ -e "$dest/$short" ]; then
cd $dest/$short
git fetch origin "+refs/heads/*:refs/heads/*" --prune
else
mkdir -p $dest
cd $dest
git clone --mirror $long $short
fi
}
# backup a repo from github
githubbk ()
{
status processing $1 from github
gitbk git@github.com:$1 $DEST/github
}
# Stage 1 : Backup repos hosted on ma
# TODO: don't use ls here (see http://mywiki.wooledge.org/ParsingLs)
repos=$(ssh ma ls \$HOME/local/git)
for repo in $repos; do
status processing $repo from ma
# TODO: maybe just move all gcrypt repos into a separate dir and
# then loop through them (only have one right now so not worth it)
if [ "$repo" = "priv.git" ]; then
gitbk gcrypt::ssh://ma/~/local/git/$repo $DEST/ma
else
gitbk ma:local/git/$repo $DEST/ma
fi
done
# Stage 2 : Backup some repos hosted on github (the ones I care about).
# TODO: consider using joeyh's github-backup program
githubbk spwhitton/dotfiles.git
githubbk spwhitton/propellor.git
githubbk spwhitton/sariulclocks.git
githubbk spwhitton/srem.git
githubbk spwhitton/oso2pdf.git
githubbk spwhitton/pandoc-citeproc-preamble.git
# Stage 3 : Backup other repos ad hoc
status processing blog comments
gitbk ma:html/blog/comments $DEST/other
|