diff options
author | heqnx <root@heqnx.com> | 2025-05-27 22:08:47 +0300 |
---|---|---|
committer | heqnx <root@heqnx.com> | 2025-05-27 22:08:47 +0300 |
commit | f1a0d2eb829cc0cb9beaf08371605d68734f2a35 (patch) | |
tree | d1eb4863cd51cd22c7eaa2c4c4410fb7b6d79c67 | |
parent | cc34ae34b753ebaa13519500fc029e4c43fa025f (diff) | |
download | cgit-f1a0d2eb829cc0cb9beaf08371605d68734f2a35.tar.gz cgit-f1a0d2eb829cc0cb9beaf08371605d68734f2a35.zip |
added cgit-backup.sh
-rw-r--r-- | cgit-backup.sh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cgit-backup.sh b/cgit-backup.sh new file mode 100644 index 0000000..73eab0c --- /dev/null +++ b/cgit-backup.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# stages: +# - backup +# +# backup_cgit: +# stage: backup +# image: alpine:latest +# before_script: +# - apk add --no-cache bash curl git +# - git config --global user.name "GitLab CI" +# - git config --global user.email "ci@gitlab.com" +# - git remote set-url origin "https://oauth2:${TOKEN}@gitlab.com/user/repo.git" +# script: +# - /bin/bash cgit-backup.sh +# - git checkout main || git checkout -b main +# - git add repos/ +# - git commit -m "Backup cgit repositories $(date -u +'%Y-%m-%d %H:%M:%S UTC')" || true +# - git push origin main -o ci.skip +# only: +# - schedules +# variables: +# GIT_STRATEGY: clone + + +cgit="https://cgit.heqnx.com" + +mkdir -p repos + +repos=$(curl -sSL "${cgit}" | grep -o "<a href='/[^']*/'>" | sed -E "s/^<a href='([^']*)'>/\1/" | sort -u) + +while IFS= read -r repo_path; do + repo_name=$(basename "${repo_path}") + repo_url="${cgit}${repo_path}" + repo_dir="repos/${repo_name}" + + printf "%s\n" "[inf] processing ${repo_url}" + + if test -d "${repo_dir}"; then + if test -d "${repo_dir}/.git.bak"; then + printf "%s\n" "[inf] restoring .git from .git.bak for ${repo_name}" + mv "${repo_dir}/.git.bak" "${repo_dir}/.git" + fi + printf "%s\n" "[inf] fetching updates for ${repo_name}" + git -C "${repo_dir}" fetch origin + git -C "${repo_dir}" reset --hard origin/HEAD + else + printf "%s\n" "[inf] cloning ${repo_name}" + git -C repos clone "${repo_url}" + fi + + if test -d "${repo_dir}/.git"; then + printf "%s\n" "[inf] moving .git to .git.bak for ${repo_name}" + mv "${repo_dir}/.git" "${repo_dir}/.git.bak" + fi + +done <<< "${repos}" |