|
| 1 | +name: Backup and Restore |
| 2 | +run-name: ${{ github.actor }} running backup and restore operation |
| 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: true |
| 13 | + type: string |
| 14 | + default: 'master' |
| 15 | + workflow_call: |
| 16 | + inputs: |
| 17 | + hostname: |
| 18 | + description: 'Hostname' |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + ref: |
| 22 | + description: 'Ref' |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + default: 'master' |
| 26 | + |
| 27 | +jobs: |
| 28 | + build: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v3 |
| 32 | + with: |
| 33 | + repository: github/backup-utils-private |
| 34 | + ref: ${{ inputs.ref }} |
| 35 | + token: ${{ secrets.BACKUPUTILACCESS }} |
| 36 | + - run: docker build . --file Dockerfile --tag backup-utils |
| 37 | + - run: docker save backup-utils -o backup-utils.tar |
| 38 | + - uses: actions/upload-artifact@v3 |
| 39 | + with: |
| 40 | + name: backup-utils |
| 41 | + path: backup-utils.tar |
| 42 | + backup-utils-backup-and-restore: |
| 43 | + needs: build |
| 44 | + runs-on: ubuntu-latest |
| 45 | + env: |
| 46 | + SSH_KEY: ${{ secrets.BACKUP_SSH_KEY }} |
| 47 | + steps: |
| 48 | + - uses: actions/download-artifact@v3 |
| 49 | + with: |
| 50 | + name: backup-utils |
| 51 | + - name: Load docker container |
| 52 | + run: docker load -i backup-utils.tar |
| 53 | + - uses: actions/checkout@v3 |
| 54 | + - name: Create backup directory |
| 55 | + run: mkdir $HOME/ghe-backup-data |
| 56 | + - name: set up ssh SSH_KEY |
| 57 | + run: echo -e "${SSH_KEY}\n" > $HOME/backup |
| 58 | + - name: set up ssh key permissions |
| 59 | + run: chmod 0600 $HOME/backup |
| 60 | + - name: change version |
| 61 | + run: echo "3.8.0" > $HOME/version |
| 62 | + - name: Perform backup |
| 63 | + run: | |
| 64 | + docker run -e "GHE_HOSTNAME=${{ inputs.hostname }}" \ |
| 65 | + -e "GHE_DATA_DIR=/data" \ |
| 66 | + -e "GHE_EXTRA_SSH_OPTS=-p 122 -i /ghe-ssh/id_rsa -o ServerAliveInterval=30 -o ServerAliveCountMax=12000 -o StrictHostKeyChecking=no" \ |
| 67 | + -e "GHE_NUM_SNAPSHOTS=15" \ |
| 68 | + -v "$HOME/ghe-backup-data:/data" \ |
| 69 | + -v "$HOME/backup:/ghe-ssh/id_rsa" \ |
| 70 | + -v "$HOME/version:/backup-utils/share/github-backup-utils/version" \ |
| 71 | + --rm \ |
| 72 | + backup-utils ghe-backup |
| 73 | + - name: Prepare for restore |
| 74 | + run: ssh -p122 -i $HOME/backup -o StrictHostKeyChecking=no admin@${{ inputs.hostname }} "ghe-maintenance -s" |
| 75 | + - name: Restore data to instance |
| 76 | + run: | |
| 77 | + docker run -e "GHE_HOSTNAME=${{ inputs.hostname }}" \ |
| 78 | + -e "GHE_DATA_DIR=/data" \ |
| 79 | + -e "GHE_EXTRA_SSH_OPTS=-p 122 -i /ghe-ssh/id_rsa -o ServerAliveInterval=30 -o ServerAliveCountMax=12000 -o StrictHostKeyChecking=no" \ |
| 80 | + -e "GHE_NUM_SNAPSHOTS=15" \ |
| 81 | + -v "$HOME/ghe-backup-data:/data" \ |
| 82 | + -v "$HOME/backup:/ghe-ssh/id_rsa" \ |
| 83 | + -v "$HOME/version:/backup-utils/share/github-backup-utils/version" \ |
| 84 | + --rm \ |
| 85 | + backup-utils ghe-restore ${{ inputs.hostname }} |
| 86 | + - name: Reset maintenance mode after restore |
| 87 | + run: ssh -p122 -i $HOME/backup -o StrictHostKeyChecking=no admin@${{ inputs.hostname }} "ghe-maintenance -u" |
| 88 | + |
0 commit comments