apiVersion: batch/v1
kind: CronJob
metadata:
name: xata-clone
namespace: xata-clone # change if needed
spec:
schedule: "0 0 * * *" # change if needed
jobTemplate:
spec:
template:
spec:
containers:
- name: xata-clone
image: ubuntu:latest
env:
- name: XATA_CLI_SOURCE_POSTGRES_URL
valueFrom:
secretKeyRef:
name: xata-secrets
key: source-postgres-url
- name: XATA_API_REFRESH_TOKEN
valueFrom:
secretKeyRef:
name: xata-secrets
key: XATA_API_REFRESH_TOKEN
- name: XATA_ORGANIZATIONID
valueFrom:
secretKeyRef:
name: xata-secrets
key: XATA_ORGANIZATIONID
- name: XATA_PROJECTID
valueFrom:
secretKeyRef:
name: xata-secrets
key: XATA_PROJECTID
- name: XATA_BRANCHNAME
valueFrom:
secretKeyRef:
name: xata-secrets
key: XATA_BRANCHNAME
- name: XATA_DATABASENAME
valueFrom:
secretKeyRef:
name: xata-secrets
key: XATA_DATABASENAME
command:
- /bin/bash
- -c
- |
set -e
echo "Installing dependencies"
apt-get update && \
apt-get install -y curl jq perl gnupg lsb-release && \
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql.gpg && \
echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install -y postgresql-client-17
echo "Installing Xata CLI"
curl -fsSL https://xata.io/install.sh | bash
export PATH="$HOME/.config/xata/bin/:$PATH"
xata init --organization $XATA_ORGANIZATIONID --project $XATA_PROJECTID --database $XATA_DATABASENAME
xata status --json
echo "Checking out branch: $XATA_BRANCHNAME"
xata branch checkout "$XATA_BRANCHNAME"
echo "Updated status:"
xata status
xata branch view
echo "Starting clone..."
xata clone start --source-url "$XATA_CLI_SOURCE_POSTGRES_URL" --validation-mode=relaxed
restartPolicy: OnFailure