diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f81d0b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bkup/ +fromCygwin/ +log/ + diff --git a/GitLabBackup.py b/GitLabBackup.py old mode 100755 new mode 100644 index fc05b3b..45c45a8 --- a/GitLabBackup.py +++ b/GitLabBackup.py @@ -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() @@ -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) diff --git a/run_backup.sh b/run_backup.sh new file mode 100755 index 0000000..316cccd --- /dev/null +++ b/run_backup.sh @@ -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 +