forked from simonwalz/script-git-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup-gitlab
More file actions
executable file
·61 lines (56 loc) · 1.46 KB
/
backup-gitlab
File metadata and controls
executable file
·61 lines (56 loc) · 1.46 KB
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
#!/bin/sh
GITLAB_HOST="$1"
GITLAB_TOKEN="$2"
PREFIX="$3"
EXCLUDE_REPOS="$4"
GIT_MIRROR="true"
GITLAB_HTTP_PROTO="https"
FETCH_PROTO="ssh"
GITLAB_USER="git"
CURL_OPTS=""
if test "x${GITLAB_HOST}" = "x" || test "x{GITLAB_TOKEN}" = "x"
then
echo "Usage: $0 GITLAB_HOST GITLAB_TOKEN LOCAL_PATH_PREFIX [EXCLUDE_REPOS] [GITLAB_HTTP_PROTO] [FETCH_PROTO] [FETCH_USER] [CURL_OPTS] [GIT_MIRROR]"
exit 2
fi
if test "x$5" != "x"
then
GITLAB_HTTP_PROTO="$5"
fi
if test "x$6" != "x"
then
FETCH_PROTO="$6"
fi
if test "x$7" != "x"
then
GITLAB_USER="$7"
fi
if test "x$8" != "x"
then
CURL_OPTS="$8"
fi
if test "x$9" = "xfalse"
then
GIT_MIRROR="false"
fi
GITLAB_HTTP="${GITLAB_HTTP_PROTO}://${GITLAB_HOST}/"
GITLAB_URL="${GITLAB_USER}@${GITLAB_HOST}:"
if test "x${FETCH_PROTO}" = "xhttp" || test "x${FETCH_PROTO}" = "xhttps"
then
GITLAB_URL="${FETCH_PROTO}://${GITLAB_USER}:${GITLAB_TOKEN}@${GITLAB_HOST}/"
fi
REPOS="$(curl ${CURL_OPTS} -s -f -H "Private-token: $GITLAB_TOKEN" "${GITLAB_HTTP}api/v4/projects?membership=true&per_page=999" | php -r 'echo join("\n",array_map(function($a){return $a["path_with_namespace"];},json_decode(file_get_contents("php://stdin"),1)))."\n";')"
for r in $REPOS
do
ignore=0
if test "x${EXCLUDE_REPOS}" != "x"; then
echo "${r}" | grep -E "${EXCLUDE_REPOS}" >/dev/null
if test "x$?" = "x0"; then
echo "# ignore repo: ${r}"
ignore=1
fi
fi
if test "x${ignore}" != "x1"; then
backup-git-repo "${GITLAB_URL}${r}.git" "${PREFIX}${r}" "${GIT_MIRROR}"
fi
done