Skip to content

Commit 31adb30

Browse files
fauustgrooverdan
authored andcommitted
MDBF-1000: implement an export for the server repository
No MariaDB server code is touched here, this is only about GitHub actions CI.
1 parent 923094b commit 31adb30

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/backup.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: backup
3+
4+
on:
5+
schedule:
6+
- cron: "32 02 * * *"
7+
8+
jobs:
9+
backup:
10+
runs-on: ubuntu-latest
11+
env:
12+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
13+
REPO: ${{ github.repository }}
14+
RESTIC_PASSWORD: ${{ secrets.RESTIC_PASSWORD }}
15+
RESTIC_REPOSITORY_URL: ${{ secrets.RESTIC_REPOSITORY }}
16+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
17+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
18+
steps:
19+
- name: Install requirements
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get -y install restic
23+
- name: Trigger backup export
24+
run: |
25+
ID=$(gh api --method POST /org/MariaDB/migrations \
26+
--raw-field "repositories[]=$REPO" \
27+
--field lock_repositories=false \
28+
--field exclude_git_data=true --jq '.id')
29+
# define some ENV vars needed below
30+
echo "EXPORT_ID=$ID" >>$GITHUB_ENV
31+
echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
32+
- name: Wait until backup is finished
33+
run: |
34+
while true; do
35+
STATE=$(gh api --method GET "/user/migrations/$EXPORT_ID" --jq '.state')
36+
[[ $STATE == "exported" ]] && break
37+
sleep 10
38+
done
39+
- name: Download backup
40+
run: |
41+
ARCHIVE_URL=$(gh api --method GET "/org/MariaDB/migrations/$EXPORT_ID" --jq '.archive_url')
42+
curl -L -H "Accept: application/vnd.github+json" \
43+
-H "Authorization: Bearer $GH_TOKEN" \
44+
-H "X-GitHub-Api-Version: 2022-11-28" \
45+
-o "archive.tgz" "$ARCHIVE_URL"
46+
- name: Save backup (restic)
47+
run: |
48+
export RESTIC_REPOSITORY=$RESTIC_REPOSITORY_URL/$REPO_NAME
49+
# init repository if necessary
50+
if ! restic cat config >/dev/null 2>&1; then
51+
restic init
52+
fi
53+
restic backup --host gh-runner --stdin --stdin-filename archive.tgz <./archive.tgz
54+
restic forget --prune --keep-within 6m
55+
restic check

0 commit comments

Comments
 (0)