-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_git
executable file
·73 lines (60 loc) · 2.01 KB
/
backup_git
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
#!/usr/bin/env bash
# backup by cloning
# create clone with 'cd /Volumes/Elvis/backups/cdh; git clone --mirror ~/git/cdh/hive'
# or: git clone --mirror asherman-impala-gce-ubuntu16.gce.cloudera.com:git/asf/Impala Impala.gce.git
#
# try 'git config gc.auto 256' to force more packing
# see https://stackoverflow.com/questions/16337498/understanding-git-gc-auto
#
function error_exit {
echo "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2:-1}" ## Return a code specified by $2 or 1 by default.
}
while getopts g opts; do
case ${opts} in
g)
GC=true
;;
*)
echo "usage: $0 [-g]"
exit 0
;;
esac
done
# where backups are stored
BACKUP_HOME=/Volumes/Elvis/backups
cd $BACKUP_HOME || error_exit "cannot cd to $BACKUP_HOME you may be on the wrong computer"
# set REPO_NAMES to a list of repositories to to look at
. $(dirname "$0")/repos.sh
for repoName in "${REPO_NAMES[@]}"
do
repos=${BACKUP_HOME}/$repoName
echo $repos
cd $repos
# should this be git remote update -p ??
# that will remove branches that have been removed remotely
# That can prevent errors where people have recreated branches
# but means we don't keep a record of my branches forever.
git remote update
if [ -z "$GC" ]
then
# echo no gc
# I don't know if this config even works
git config gc.pruneExpire 52.weeks.ago
git config gc.reflogExpireUnreachable 24.months.ago
# I think this helps pack more often
git config --local gc.auto 256
# git prune fixed a one-time problem but it takes too much time
# git prune
git gc --auto
else
# echo with gc
chflags -R nouchg *
git gc
# if you see
# warning: unable to unlink ./objects/ff/d0439f332f0ac20314b6f413e149596b493411: Operation not permitted
# then run
# chflags -R nouchg *
fi
echo '------------------------'
done