Skip to content

Commit

Permalink
Update backup.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mgz0227 authored May 3, 2024
1 parent c56f075 commit e721999
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions .github/workflows/backup.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
name: Backup main branch
name: Backup Main Branch

on:
push:
branches: [main]
branches:
- main

jobs:
backup_main_branch:
name: Backup main branch
backup:
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: main

- name: Backup main branch as tar.gz
run: |
git archive --format=tar.gz --output=main_backup_$(date +"%Y%m%d%H%M%S").tar.gz main
mkdir -p backups
mv main_backup_*.tar.gz backups/
shell: bash
- name: Checkout main branch
uses: actions/checkout@v2
with:
ref: main

- name: Push main branch backup to backup branch
run: |
git config --local user.email "miaogongzi0227@gmail.com"
git config --local user.name "mgz0227"
git remote add backup_origin https://github.com/mgz0227/legado-Harmony.git
git fetch backup_origin
git checkout -b backup_branch backup_origin/backup || git checkout -b backup_branch
mv backups/main_backup_*.tar.gz ./
git add main_backup_*.tar.gz
git commit -m "Backup main branch at $(date)"
git push backup_origin backup_branch
git checkout main
shell: bash
- name: Archive main branch as tar.gz
run: |
tar -czf main_backup_$(date +"%Y%m%d").tar.gz *
working-directory: ${{ github.workspace }}

- name: Create and push backup branch
run: |
git config --local user.email "miaogongzi0227@gmail.com"
git config --local user.name "mgz0227"
git branch -D backup || true
git checkout -b backup
git add main_backup_$(date +"%Y%m%d").tar.gz
git commit -m "Backup main branch as of $(date +"%Y-%m-%d")"
git push origin backup

0 comments on commit e721999

Please sign in to comment.