Repository Backup #41
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: Repository Backup | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs daily at midnight UTC | |
workflow_dispatch: # Allows manual trigger | |
jobs: | |
backup: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # This gives permission to push to the repository | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history | |
- name: Configure Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Create and push backup | |
run: | | |
# Ensure .backup directory exists | |
mkdir -p .backup | |
# Create timestamp for backup name | |
TIMESTAMP=$(date +%Y%m%d_%H%M%S) | |
BACKUP_FILE=".backup/backup_${TIMESTAMP}.bundle" | |
# Create git bundle backup | |
git bundle create "${BACKUP_FILE}" --all | |
# Clean up old backups (keep last 7) | |
cd .backup | |
ls -t *.bundle 2>/dev/null | tail -n +8 | xargs -r rm | |
cd .. | |
# Stage, commit and push | |
git add .backup/ | |
git commit -m "Automated backup ${TIMESTAMP}" | |
git push |