# How to schedule volume snapshots and restore data

Source: https://docs.quake.ai/docs/block/how-to/schedule-snapshots-and-restore
Markdown: https://docs.quake.ai/docs/block/how-to/schedule-snapshots-and-restore.md

---

# How to schedule volume snapshots and restore data

Schedule recurring Cinder volume snapshots with cron on a control instance or a CI workflow. Set a retention period, remove expired snapshots, and test restores on a recovery volume.

<PrerequisiteBlock methods={["console", "cli", "api"]}>

- A [block volume](/docs/block/how-to/create-volume) attached or available for snapshot
- A place to run the scheduler: a small Quake AI instance or an external CI runner with [application credentials](/docs/tools/generate-app-credentials)

</PrerequisiteBlock>

## Create a snapshot manually

See [How to create a volume snapshot](/docs/block/how-to/create-snapshot) for the Console, CLI, and API paths.

## Schedule with cron on an instance

On a tooling VM in the same project, open the cron configuration:

```bash
crontab -e
```

Add this cron entry to create a snapshot at 02:00 UTC each night:

```cron
0 2 * * * openstack volume snapshot create --volume MY_VOLUME --force --description "nightly-$(date +\%F)" nightly-$(date +\%F)
```

Source OpenStack credentials from `/etc/openstack/env`, and restrict the file to its owner with `chmod 600`. Use an application credential for the job.

### Retention loop

Delete snapshots older than seven days:

```bash
openstack volume snapshot list -f value -c ID -c Name | while read -r id name; do
  case "$name" in nightly-*)
    # parse date from name and delete when older than retention window
    openstack volume snapshot delete "$id"
  ;; esac
done
```

Run the retention script weekly from the same cron user.

## Schedule with GitHub Actions

```yaml
on:
  schedule:
    - cron: '0 2 * * *'
jobs:
  volume-snapshot:
    runs-on: ubuntu-latest
    steps:
      - run: pip install python-openstackclient
      - run: openstack volume snapshot create --volume "$VOLUME_ID" --force "ci-$(date +%F)"
        env:
          OS_AUTH_URL: ${{ secrets.OS_AUTH_URL }}
          OS_AUTH_TYPE: v3applicationcredential
          OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
          OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
          OS_REGION_NAME: ${{ secrets.OS_REGION_NAME }}
          OS_PROJECT_ID: ${{ secrets.OS_PROJECT_ID }}
```

See [Deploy an application from CI](/docs/automation/how-to/app-cicd-vm) for secret naming patterns.

## Restore from a snapshot

1. Create a new volume from the snapshot ([create volume](/docs/block/how-to/create-volume) with `--snapshot` source).
2. Attach the volume to a recovery instance.
3. Mount the filesystem and verify data, or replace the production volume during a maintenance window.
4. Run an application-level restore drill (database consistency check, file checksum).

## See also

- [How to create a volume snapshot](/docs/block/how-to/create-snapshot)
- [How to back up and restore a Quake AI VM](/docs/compute/how-to/backup-and-restore)
- [How to schedule cron jobs on a VM](/docs/compute/how-to/schedule-cron-jobs)
