GitHub Action
Scheduled snapshot restoration
Using Snaplet with GitHub Actions is a powerful combination to automate your development infrastructure requirements, like keeping a staging database automatically updated.
In this tutorial we'll show you how to create a GitHub Actions Workflow to capture a snapshot from your source database, and restore it to your target database at 4am every morning.
In order to restore snapshots you'll need:
- Setup a source database in Snaplet
- You've run the
snaplet setup
command in your GitHub repository, which created a.snaplet/config.json
file. This file associates your repository with your snapshots. - A Snaplet CLI access token (opens in a new tab).
- A target database with superuser priviledges and a connection string to that database.
Create a GitHub Actions Workflow
This GitHub Actions Workflow will capture a new snapshot in the cloud at 4am every day.
It installs the Snaplet CLI and runs the snaplet snapshot create -y
command.
- Create a
.github/workflows
directory in your repository on GitHub if this directory does not already exist. - In the
.github/workflows
directory, create a file namedsnaplet-restore.yml
. - Copy the following yaml into
snaplet-restore.yml
:
This workflow runs every morning at 4am, and can also be manually triggered (opens in a new tab)
It checks out the repository, in order to access the projectId
from .snaplet/config.json
, then it installs the Snaplet CLI and runs the snaplet snapshot create
command.
Use snaplet snapshot restore -y
instead to restore the last captured snapshot rather than creating a new one.
Adding Secrets to GitHub
We're almost done. The last step is to securely add SNAPLET_DATA_TARGET_DB_URL
secrets to our GitHub repository.
- On GitHub.com, navigate to the main page of your GitHub repository.
- Under your repository name, click on Settings.
- In the left sidebar, click Secrets.
- Click New repository secret.
- Type a name for your secret in the Name input box and enter the value for your secret.
- Click Add Secret.