Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bkup/
fromCygwin/
log/

6 changes: 3 additions & 3 deletions GitLabBackup.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

while True:
# Request GitLab API to retrieve projects
gitlab_url = args.url + "/api/v3/projects?page=" + str(page) + "&private_token=" + args.token
r = requests.get(gitlab_url, verify=False)
gitlab_url = args.url + "/api/v4/projects?visibility=private&page=" + str(page) + "&private_token=" + args.token
r = requests.get(gitlab_url, verify=True)
if r.status_code != 200:
r.raise_for_status()

Expand All @@ -47,7 +47,7 @@
url = project["ssh_url_to_repo"]
if args.ssh_port:
url = "ssh://" + url.replace(":", ":" + args.ssh_port + "/")
localPath = backup_directory + "/" + project["path"] + ".git"
localPath = backup_directory + "/" + project["path_with_namespace"] + ".git"
if not os.path.exists(localPath):
print("Create backup for " + localPath)
os.system("git clone --mirror " + url + " " + localPath)
Expand Down
28 changes: 28 additions & 0 deletions run_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# This is run from cron by /etc/cron.d/CTR-git-backup
# Or run immediately with
# # sudo -i -u gitbackup /data/backups/wbic-git-backup/GitLabBackup/run_backup.sh

# EDIT CONFIGURATION HERE:
ROOTDIR=/data/backups/wbic-git-backup/GitLabBackup
# API KEY must be stored in api.key file with limited permissions
APIKEY=$(< $ROOTDIR/../keys/api.key)
LOGDIR="$ROOTDIR/log"
LOGFILE="$LOGDIR/GitLabBackup.log"


cd "$ROOTDIR"

[ ! -d "$LOGDIR" ] && mkdir "$LOGDIR" && echo "Log folder '$LOGDIR' created successfully."

date "+GitLabBackup running at %Y%m%d-%H%M%S" >> "$LOGFILE"
echo " running as $(id)" >> "$LOGFILE"

DESTDIR="$ROOTDIR/bkup/auto-$(date +%A)"
echo " DESTDIR=$DESTDIR" >> "$LOGFILE"

[ ! -d "$DESTDIR" ] && mkdir "$ROOTDIR/bkup/auto-$(date +%A)"

export GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i $ROOTDIR/../keys/wbic-backup-key"
exec /usr/bin/python3 GitLabBackup.py --backup_dir bkup/auto-$(date +%A) -- https://gitlab.com "$APIKEY" >> "$LOGFILE" 2>&1