Skip to content

Commit

Permalink
Use variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
sKoreman committed Nov 6, 2024
1 parent f57b209 commit bc733cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion util/backup-github/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM voormedia/backup-base:latest

RUN \
apk add --no-cache \
git \
github-cli

COPY backup-github.sh /srv
Expand Down
22 changes: 12 additions & 10 deletions util/backup-github/backup-github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,34 @@ FILENAME="git_repositories_${DATE}"
mkdir "/tmp/${FILENAME}"
cd "/tmp/${FILENAME}"


REPOS=$(gh repo list "${GITHUB_ACCOUNT}" --source --limit 100000 --json name | jq -r -c '.[] | .name')

if [ -n "$REPOSITORY_PREFIX" ]; then
echo "Filtering on repositories with prefix '${REPOSITORY_PREFIX}'."
fi

for REPO in $REPOS; do
if [[ $NAME == "${REPOSITORY_PREFIX}"* ]]; then
gh repo clone "${GITHUB_ACCOUNT}/${NAME}" -- --mirror
cd "${NAME}.git"
if [[ $REPO == "${REPOSITORY_PREFIX}"* ]]; then
echo "Backing up repository: ${REPO} for ${GITHUB_ACCOUNT}."
gh repo clone "${GITHUB_ACCOUNT}/${REPO}" -- --mirror
cd "${REPO}.git"

if [[ -n "$(git rev-list --branches)" ]]; then
# Check if there are any commits.
git bundle create "../${NAME}.pack" --all
git bundle create "../${REPO}.pack" --all
cd ..

zip -r9 "/tmp/${FILENAME}/${NAME}.zip" "/tmp/${FILENAME}/${NAME}.pack"
openssl aes-256-cbc -md md5 -in "/tmp/${FILENAME}/${NAME}.zip" -out "/tmp/${FILENAME}/${NAME}.zip.encrypted" -pass "pass:${B2_ENCRYPTION_KEY}"
b2 file upload "${B2_BUCKET}" "/tmp/${FILENAME}/${NAME}.zip.encrypted" "${NAME}/${DATE}.zip.encrypted"
zip -r9 "/tmp/${FILENAME}/${REPO}.zip" "/tmp/${FILENAME}/${REPO}.pack"
openssl aes-256-cbc -md md5 -in "/tmp/${FILENAME}/${REPO}.zip" -out "/tmp/${FILENAME}/${REPO}.zip.encrypted" -pass "pass:${B2_ENCRYPTION_KEY}"
b2 file upload "${B2_BUCKET}" "/tmp/${FILENAME}/${REPO}.zip.encrypted" "${REPO}/${DATE}.zip.encrypted"
else
echo "Skipping empty repository ${NAME}."
echo "Skipping empty repository ${REPO}."
cd ..
fi

rm -rf "/tmp/${FILENAME}/${NAME}.git"
rm -f "/tmp/${FILENAME}/${NAME}".*
rm -rf "/tmp/${FILENAME}/${REPO}.git"
rm -f "/tmp/${FILENAME}/${REPO}".*
fi
done

Expand Down

0 comments on commit bc733cd

Please sign in to comment.