Skip to main content
This workflow helps you clone your database on a schedule or manually trigger it. It’s useful for creating regular backups or setting up test environments.

Workflow configuration

Authentication and environment variables

The workflow requires several environment variables to be set:
  • XATA_API_KEY: Your Xata API key (set as a GitHub secret)
  • XATA_ORGANIZATION_ID: Your Xata organization ID
  • XATA_PROJECT_ID: Your Xata project ID
  • XATA_BRANCH_ID: The ID of the main branch
  • XATA_BRANCH_NAME: The name of the main branch
  • XATA_DATABASE_NAME: Your database name
  • XATA_CLI_SOURCE_POSTGRES_URL: The source PostgreSQL database URL (set as a GitHub secret)
If you have the Xata CLI configured with your project locally, you can obtain these values with the following commands:

Workflow steps

1. Checkout code

This step checks out your repository code with full history and proper credentials configuration.

2. Install Xata CLI

This step installs the Xata CLI using the official installer script and adds it to the GitHub Actions PATH.

3. Check Xata status

This step verifies that your Xata CLI is properly configured and can connect to your database. For more details, see:

4. Checkout clone branch

This step:
  • Checks out the clone_demo branch
  • Extracts the branch ID using jq
  • Stores it in an environment variable

5. Start clone process

This step initiates the cloning process from your source PostgreSQL database. For more details, see the clone start command documentation.

Triggering the workflow

The workflow can be triggered in two ways:
  1. Scheduled run
    Runs daily at 8:00 AM UTC
  2. Manual trigger
    Can be triggered manually from the GitHub Actions UI

Concurrency control

The workflow uses GitHub Actions concurrency to prevent multiple runs from interfering with each other:
This ensures that:
  • Only one workflow run is active at a time
  • New runs cancel any in-progress runs
  • Prevents race conditions during cloning

Best practices

  1. Set appropriate timeout
    • The workflow has a 10-minute timeout
    • Adjust based on your database size and cloning duration
  2. Use environment variables
    • Store sensitive information in GitHub secrets
    • Use environment variables for configuration
  3. Schedule regular clones
    • Set up a schedule that matches your backup needs
    • Consider your database size and update frequency