Skip to content

Commit 4258712

Browse files
Add backup workflow
1 parent 356725a commit 4258712

File tree

2 files changed

+118
-7
lines changed

2 files changed

+118
-7
lines changed

.github/workflows/backup.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Backup
2+
run-name: ${{ github.actor }} run backup and upload to ghes-data
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
hostname:
7+
description: 'Hostname'
8+
required: true
9+
type: string
10+
ref:
11+
description: 'Ref'
12+
required: false
13+
type: string
14+
default: 'master'
15+
workflow_call:
16+
inputs:
17+
size:
18+
description: 'Size of the dataset to restore'
19+
required: false
20+
type: string
21+
default: 'small'
22+
hostname:
23+
description: 'Hostname of the server'
24+
required: true
25+
type: string
26+
ref:
27+
description: 'Branch ref to use'
28+
required: false
29+
type: string
30+
default: 'master'
31+
version:
32+
description: 'GHES Version of dataset'
33+
required: false
34+
type: string
35+
default: "3.8.0"
36+
37+
jobs:
38+
build:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v3
42+
with:
43+
repository: github/backup-utils-private
44+
ref: ${{ inputs.ref }}
45+
token: "${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}"
46+
- run: docker build . --file Dockerfile --tag backup-utils
47+
- run: docker save backup-utils -o backup-utils.tar
48+
- uses: actions/upload-artifact@v3
49+
with:
50+
name: backup-utils
51+
path: backup-utils.tar
52+
backup-utils-backup:
53+
needs: build
54+
runs-on: ubuntu-latest
55+
env:
56+
SSH_KEY: ${{ secrets.BACKUP_SSH_KEY }}
57+
steps:
58+
- uses: actions/download-artifact@v3
59+
with:
60+
name: backup-utils
61+
- name: Load docker container
62+
run: docker load -i backup-utils.tar
63+
- uses: actions/checkout@v3
64+
- name: Create backup directory
65+
run: mkdir $HOME/ghe-backup-data
66+
- name: set up ssh SSH_KEY
67+
run: echo -e "${SSH_KEY}\n" > $HOME/backup
68+
- name: set up ssh key permissions
69+
run: chmod 0600 $HOME/backup
70+
- name: change version
71+
run: echo "3.8.0" > $HOME/version
72+
- name: Perform backup
73+
run: |
74+
docker run -e "GHE_HOSTNAME=${{ inputs.hostname }}" \
75+
-e "GHE_DATA_DIR=/data" \
76+
-e "GHE_EXTRA_SSH_OPTS=-p 122 -i /ghe-ssh/id_rsa -o ServerAliveInterval=30 -o ServerAliveCountMax=12000 -o StrictHostKeyChecking=no" \
77+
-e "GHE_NUM_SNAPSHOTS=15" \
78+
-v "$HOME/ghe-backup-data:/data" \
79+
-v "$HOME/backup:/ghe-ssh/id_rsa" \
80+
-v "$HOME/version:/backup-utils/share/github-backup-utils/version" \
81+
--rm \
82+
backup-utils ghe-backup
83+
84+
- uses: actions/checkout@v3
85+
with:
86+
path: ghes-data
87+
repository: github/ghes-data
88+
ref: main
89+
token: "${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}"
90+
lfs: 'true'
91+
92+
- name: Zip backup
93+
run: |
94+
ls -al $HOME/ghe-backup-data
95+
dirname=$(find $HOME/ghe-backup-data/ -type d -maxdepth 1 -mindepth 1)
96+
echo $dirname
97+
tar -czvf $dirname.tar.gz $dirname
98+
cp $dirname.tar.gz ghes-data/data/backup/{{inputs.size}}/v{{inputs.version}}/$dirname.tar.gz
99+
100+
- name: Upload backup to ghes-data
101+
run: |
102+
cd ghes-data/data/backup/{{inputs.size}}/v{{inputs.version}}
103+
git add .
104+
git commit -am "Added new backup from automation"
105+
git push
106+
107+
108+

.github/workflows/restore.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ jobs:
5454
repository: github/backup-utils-private
5555
ref: ${{ inputs.ref }}
5656
token: "${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}"
57+
5758
- run: docker build . --file Dockerfile --tag backup-utils
5859
- run: docker save backup-utils -o backup-utils.tar
60+
5961
- uses: actions/upload-artifact@v3
6062
with:
6163
name: backup-utils
6264
path: backup-utils.tar
65+
6366
restore:
6467
needs: build
6568
runs-on: ubuntu-latest
@@ -69,8 +72,10 @@ jobs:
6972
- uses: actions/download-artifact@v3
7073
with:
7174
name: backup-utils
75+
7276
- name: Load docker container
7377
run: docker load -i backup-utils.tar
78+
7479
- uses: actions/checkout@v3
7580
with:
7681
path: ghes-data
@@ -79,30 +84,27 @@ jobs:
7984
token: "${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}"
8085
lfs: 'true'
8186

82-
- name: Create backup directory
83-
run: |
84-
85-
86-
- name: Unzip backup
87+
- name: Unzip backup and setup symlink
8788
run: |
8889
mkdir $HOME/ghe-backup-data
8990
dir_name=$(date +%s)
9091
mkdir $HOME/ghe-backup-data/$dir_name
9192
tar -xvf ghes-data/data/backup/${{ inputs.size }}/v3.8.0/${{ inputs.size }}-refined.tar.gz -C $HOME/ghe-backup-data/$dir_name
9293
9394
ln -s $dir_name $HOME/ghe-backup-data/current
94-
ls -al $HOME/ghe-backup-data
95-
ls -al $HOME/ghe-backup-data/$dir_name
9695
9796
- name: set up ssh SSH_KEY
9897
run: echo -e "${SSH_KEY}\n" > $HOME/backup
98+
9999
- name: set up ssh key permissions
100100
run: chmod 0600 $HOME/backup
101+
101102
- name: change version
102103
run: echo "3.8.0" > $HOME/version
103104

104105
- name: Prepare for restore
105106
run: ssh -p122 -i $HOME/backup -o StrictHostKeyChecking=no admin@${{ inputs.hostname }} "ghe-maintenance -s"
107+
106108
- name: Restore data to instance
107109
run: |
108110
docker run -e "GHE_HOSTNAME=${{ inputs.hostname }}" \
@@ -114,6 +116,7 @@ jobs:
114116
-v "$HOME/version:/backup-utils/share/github-backup-utils/version" \
115117
--rm \
116118
backup-utils ghe-restore ${{ inputs.hostname }}
119+
117120
- name: Reset maintenance mode after restore
118121
run: ssh -p122 -i $HOME/backup -o StrictHostKeyChecking=no admin@${{ inputs.hostname }} "ghe-maintenance -u"
119122

0 commit comments

Comments
 (0)