Skip to content

Commit 6c92cb5

Browse files
solmazabbaspourKyFaSt
authored andcommitted
Add backup workflow
1 parent 030d1cf commit 6c92cb5

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

.github/workflows/backup.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Backup and save to Azure
2+
run-name: "${{ github.actor }} - Backup and save to Azure"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
github-hostname:
8+
description: GitHub Hostname to backup
9+
required: true
10+
type: string
11+
backup-name:
12+
description: The name of the backup to be saved in Azure storage
13+
required: false
14+
default: ""
15+
type: string
16+
secrets:
17+
BACKUP_SSH_KEY:
18+
description: SSH key to access the GitHub Enterprise instance
19+
required: true
20+
INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN:
21+
description: Token for the internal actions dx bot account
22+
required: true
23+
AZURE_USERNAME:
24+
description: Azure service principal username
25+
required: false
26+
AZURE_PASSWORD:
27+
description: Azure service principal password
28+
required: false
29+
AZURE_TENANT_ID:
30+
description: Azure tenant ID
31+
required: false
32+
AZURE_SUBSCRIPTION_ID:
33+
description: Azure subscription ID
34+
required: false
35+
CONNECTIONSTRING:
36+
description: Azure storage connection string
37+
required: false
38+
39+
40+
jobs:
41+
build:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v3
45+
with:
46+
repository: github/backup-utils-private
47+
token: "${{ secrets.INTERNAL_ACTIONS_DX_BOT_ACCOUNT_TOKEN }}"
48+
- run: docker build . --file Dockerfile --tag backup-utils
49+
- run: docker save backup-utils -o backup-utils.tar
50+
- uses: actions/upload-artifact@v3
51+
with:
52+
name: backup-utils
53+
path: backup-utils.tar
54+
55+
backup-utils-backup:
56+
needs: build
57+
runs-on:
58+
group: larger-hosted-public-runners
59+
labels: ubuntu-latest-xl
60+
env:
61+
SSH_KEY: ${{ secrets.BACKUP_SSH_KEY }}
62+
steps:
63+
- uses: actions/download-artifact@v3
64+
with:
65+
name: backup-utils
66+
- name: Load docker container
67+
run: docker load -i backup-utils.tar
68+
- uses: actions/checkout@v3
69+
- name: Create backup directory
70+
run: mkdir $HOME/ghe-backup-data
71+
- name: set up ssh SSH_KEY
72+
run: echo -e "${SSH_KEY}\n" > $HOME/backup
73+
- name: set up ssh key permissions
74+
run: chmod 0600 $HOME/backup
75+
- name: change version
76+
run: echo "3.8.0" > $HOME/version
77+
78+
- name: Perform backup
79+
run: |
80+
docker run -e "GHE_HOSTNAME=${{ inputs.github-hostname }}" \
81+
-e "GHE_DATA_DIR=/data" \
82+
-e "GHE_EXTRA_SSH_OPTS=-p 122 -i /ghe-ssh/id_rsa -o ServerAliveInterval=30 -o ServerAliveCountMax=12000 -o StrictHostKeyChecking=no" \
83+
-e "GHE_NUM_SNAPSHOTS=15" \
84+
-v "$HOME/ghe-backup-data:/data" \
85+
-v "$HOME/backup:/ghe-ssh/id_rsa" \
86+
-v "$HOME/version:/backup-utils/share/github-backup-utils/version" \
87+
--rm \
88+
backup-utils ghe-backup
89+
- name: Check the backup file
90+
run: |
91+
current=$(readlink $HOME/ghe-backup-data/current)
92+
sudo tar -czvf ${{ inputs.backup-name }}.tar.gz -C $HOME/ghe-backup-data/$current .
93+
94+
- name: Login to Azure
95+
if: ${{ inputs.backup-name }} != ""
96+
run: |
97+
az login \
98+
--service-principal \
99+
-u ${{ secrets.AZURE_USERNAME }} \
100+
-p ${{ secrets.AZURE_PASSWORD }} \
101+
--tenant ${{ secrets.AZURE_TENANT_ID }}
102+
az account set --subscription "${{ secrets.AZURE_SUBSCRIPTION_ID }}"
103+
104+
- name: Upload backup to Azure
105+
if: ${{ inputs.backup-name }} != ""
106+
run: |
107+
az storage blob upload \
108+
--account-name "ghesresults" \
109+
--container-name "ghes-data" \
110+
--name ${{ inputs.backup-name }}.tar.gz \
111+
--file ${{ inputs.backup-name }}.tar.gz \
112+
--connection-string "${{ secrets.CONNECTIONSTRING }}"

0 commit comments

Comments
 (0)