mirror of
https://github.com/MariaDB/server.git
synced 2025-04-18 21:44:20 +03:00
MDBF-1000: implement an export for the server repository
No MariaDB server code is touched here, this is only about GitHub actions CI.
This commit is contained in:
parent
923094b4cd
commit
31adb3030c
55
.github/workflows/backup.yml
vendored
Normal file
55
.github/workflows/backup.yml
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
---
|
||||
name: backup
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "32 02 * * *"
|
||||
|
||||
jobs:
|
||||
backup:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
RESTIC_PASSWORD: ${{ secrets.RESTIC_PASSWORD }}
|
||||
RESTIC_REPOSITORY_URL: ${{ secrets.RESTIC_REPOSITORY }}
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
steps:
|
||||
- name: Install requirements
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install restic
|
||||
- name: Trigger backup export
|
||||
run: |
|
||||
ID=$(gh api --method POST /org/MariaDB/migrations \
|
||||
--raw-field "repositories[]=$REPO" \
|
||||
--field lock_repositories=false \
|
||||
--field exclude_git_data=true --jq '.id')
|
||||
# define some ENV vars needed below
|
||||
echo "EXPORT_ID=$ID" >>$GITHUB_ENV
|
||||
echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
|
||||
- name: Wait until backup is finished
|
||||
run: |
|
||||
while true; do
|
||||
STATE=$(gh api --method GET "/user/migrations/$EXPORT_ID" --jq '.state')
|
||||
[[ $STATE == "exported" ]] && break
|
||||
sleep 10
|
||||
done
|
||||
- name: Download backup
|
||||
run: |
|
||||
ARCHIVE_URL=$(gh api --method GET "/org/MariaDB/migrations/$EXPORT_ID" --jq '.archive_url')
|
||||
curl -L -H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: Bearer $GH_TOKEN" \
|
||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||
-o "archive.tgz" "$ARCHIVE_URL"
|
||||
- name: Save backup (restic)
|
||||
run: |
|
||||
export RESTIC_REPOSITORY=$RESTIC_REPOSITORY_URL/$REPO_NAME
|
||||
# init repository if necessary
|
||||
if ! restic cat config >/dev/null 2>&1; then
|
||||
restic init
|
||||
fi
|
||||
restic backup --host gh-runner --stdin --stdin-filename archive.tgz <./archive.tgz
|
||||
restic forget --prune --keep-within 6m
|
||||
restic check
|
Loading…
x
Reference in New Issue
Block a user