Created
January 14, 2025 18:08
-
-
Save blackestwhite/0d31b65ab2ec543f28a4a1fe82f62d92 to your computer and use it in GitHub Desktop.
a github action to save minio contents to a git repo
This file contains hidden or 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 All MinIO Buckets and Push to GitHub | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs daily at midnight | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
backup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
ref: master | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Set up MinIO Client (mc) | |
run: | | |
curl -o mc https://dl.min.io/client/mc/release/linux-amd64/mc | |
chmod +x mc | |
./mc alias set myminio ${{ secrets.MINIO_ENDPOINT }} ${{ secrets.MINIO_ACCESS_KEY }} ${{ secrets.MINIO_SECRET_KEY }} | |
- name: List and backup all buckets | |
run: | | |
# Get a list of all buckets | |
buckets=$(./mc ls myminio | awk '{print $5}') | |
# Loop through each bucket and back it up | |
for bucket in $buckets; do | |
echo "Backing up bucket: $bucket" | |
./mc mirror myminio/$bucket ./backup/$bucket | |
done | |
- name: Commit and push backup files | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add . | |
git commit --allow-empty -m "Automated MinIO backup - $(date +'%Y-%m-%d %H:%M:%S')" | |
git push https://${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}.git master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment