Update backup.yml #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Backup Main Branch | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
backup: | |
name: Backup Main Branch | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Create Backup Directory | |
run: mkdir -p backups/main | |
- name: Copy Main Branch Code | |
run: | | |
if [ -d "backups/main" ]; then | |
cp -r !(backups) backups/main | |
else | |
cp -r * backups/main | |
fi | |
- name: Archive Main Branch Code | |
run: | | |
datetime=$(date '+%Y-%m-%d_%H-%M-%S') | |
tar -zcf main_backup_$datetime.tar.gz -C backups/main . | |
- name: Configure Git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
- name: Add Backup Branch | |
run: | | |
git checkout -b backup || git checkout backup | |
git add . | |
git commit -m "Auto backup main branch code" | |
git push origin backup | |
- name: Upload Backup Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: main_backup_$datetime | |
path: main_backup_$datetime.tar.gz |