GitHub Actions
Backup your repositories, build artifacts, and databases directly from GitHub Actions workflows.
Quick Start
name: Backup to LOX
on:
schedule:
- cron: '0 2 * * *' # Daily at 2 AM UTC
workflow_dispatch: # Allow manual trigger
jobs:
backup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create backup archive
run: tar -czf backup.tar.gz ./
- name: Upload to LOX
uses: lox-backup/action@v1
with:
api-key: ${{ secrets.LOX_API_KEY }}
file: backup.tar.gz
name: 'repo-${{ github.repository }}-${{ github.sha }}'
tags: 'github,${{ github.ref_name }}'Setup
1. Get your API Key
Get your LOX API key from backlox.com/settings/api
2. Add Secret to Repository
- Go to your repository on GitHub
- Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
LOX_API_KEY - Value: Your LOX API key
3. Create Workflow
Create a workflow file at .github/workflows/backup.yml
Action Reference
Inputs
| Input | Required | Description |
|---|---|---|
| api-key | Yes | Your LOX API key |
| file | Yes | Path to the file to backup |
| name | No | Backup name (defaults to filename) |
| description | No | Backup description |
| tags | No | Comma-separated tags |
| retention-days | No | Days to retain backup (default: 30) |
| wait | No | Wait for completion (default: true) |
| api-url | No | API URL for self-hosted instances |
Outputs
| Output | Description |
|---|---|
| uuid | Backup UUID |
| status | Final backup status |
| size | Backup size in bytes |
| checksum | SHA-256 checksum |
Examples
Backup Repository on Push to Main
name: Backup on Push
on:
push:
branches: [main]
jobs:
backup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history
- name: Create archive
run: |
tar -czf repo-backup.tar.gz \
--exclude='.git' \
--exclude='node_modules' \
--exclude='vendor' \
.
- name: Upload to LOX
uses: lox-backup/action@v1
with:
api-key: ${{ secrets.LOX_API_KEY }}
file: repo-backup.tar.gz
name: '${{ github.repository }}-${{ github.sha }}'
tags: 'github,main,${{ github.event.head_commit.author.name }}'
retention-days: 90Backup Build Artifacts
name: Build and Backup
on:
release:
types: [published]
jobs:
build-and-backup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install and Build
run: |
npm ci
npm run build
- name: Create release archive
run: |
tar -czf release-${{ github.ref_name }}.tar.gz \
dist/ \
package.json \
README.md
- name: Backup to LOX
uses: lox-backup/action@v1
with:
api-key: ${{ secrets.LOX_API_KEY }}
file: release-${{ github.ref_name }}.tar.gz
name: '${{ github.repository }}-release-${{ github.ref_name }}'
description: 'Release ${{ github.ref_name }} build artifacts'
tags: 'release,${{ github.ref_name }},production'
retention-days: 365Database Backup with MySQL
name: Database Backup
on:
schedule:
- cron: '0 3 * * *' # Daily at 3 AM
workflow_dispatch:
jobs:
backup-database:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }}
MYSQL_DATABASE: production
ports:
- 3306:3306
steps:
- name: Create database dump
run: |
mysqldump -h 127.0.0.1 -u root -p${{ secrets.MYSQL_ROOT_PASSWORD }} \
--all-databases | gzip > db-backup.sql.gz
- name: Upload to LOX
uses: lox-backup/action@v1
with:
api-key: ${{ secrets.LOX_API_KEY }}
file: db-backup.sql.gz
name: 'mysql-backup-${{ github.run_id }}'
tags: 'database,mysql,automated'
retention-days: 30Multi-File Backup with Matrix
name: Multi-Component Backup
on:
schedule:
- cron: '0 4 * * 0' # Weekly on Sunday
jobs:
backup:
runs-on: ubuntu-latest
strategy:
matrix:
component:
- name: frontend
path: ./frontend
- name: backend
path: ./backend
- name: configs
path: ./config
steps:
- uses: actions/checkout@v4
- name: Create archive
run: |
tar -czf ${{ matrix.component.name }}.tar.gz \
${{ matrix.component.path }}
- name: Upload to LOX
uses: lox-backup/action@v1
with:
api-key: ${{ secrets.LOX_API_KEY }}
file: ${{ matrix.component.name }}.tar.gz
name: '${{ github.repository }}-${{ matrix.component.name }}'
tags: '${{ matrix.component.name }},weekly'Using Outputs
name: Backup with Notification
on:
workflow_dispatch:
jobs:
backup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create archive
run: tar -czf backup.tar.gz ./
- name: Upload to LOX
id: backup
uses: lox-backup/action@v1
with:
api-key: ${{ secrets.LOX_API_KEY }}
file: backup.tar.gz
- name: Send Slack notification
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "Backup completed!",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Backup Complete*\nUUID: ${{ steps.backup.outputs.uuid }}\nSize: ${{ steps.backup.outputs.size }} bytes"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}Best Practices
Use Secrets for API Keys
Never hardcode API keys. Always use GitHub Secrets.
Use Descriptive Names
Include repository name, branch, and commit SHA in backup names for easy identification.
Exclude Unnecessary Files
Exclude node_modules, .git, build caches, and other regeneratable files to reduce backup size.
Set Appropriate Retention
Use shorter retention for frequent backups (daily), longer for releases.
Troubleshooting
Action fails with authentication error
Verify your API key is correct and the secret name matches exactly (LOX_API_KEY).
Timeout during upload
For large files, the action may timeout. Consider splitting into smaller archives or increasing workflow timeout.
File not found
Ensure the file path is relative to the workspace root. Use ls -la to debug.