BigQuery backup scripts
For the story of bqup, see our blog post!
Usage: bqup [-p PROJECT_ID] [-d TARGET_DIR] [-fvx] Options: -p PROJECT_ID, --project PROJECT_ID Project ID to load. If unspecified, defaults to current project in configuration. -d TARGET_DIR, --dir TARGET_DIR The target directory where the project will be written. Defaults to current timestamp. -f --force Overwrite target directory if it exists. -v --verbose Print a summary of the loaded project. -x --schema Export table schemata as json.
- Set up
gcloudto run with your personal account (aka run with scissors)
- Set up application-default:
gcloud auth application-default login
- Install wheel:
pip3 install wheel
pip3 install -e .(or
python3 setup.py develop)
Note: When deploying for a new GCP project, consider using Cloud Scheduler
- Turn off your host Google Instance.
- Enable BigQuery on the instance's Cloud API Access Scopes
- Start the instance.
sshinto the Google Instance you want to run
- Authorize your Compute Instance Account to read from the target BigQuery project.
bqupby cloning this repo and running
pip3 install --user -e .inside the repo.
- If it still doesn't work, check in IAM that the service account you are using has BigQuery read access.
Setting up regular backups
On the machine that will run your backups, set up your git config (username, email, the usual).
Make a directory to use as the Git repository. For this example, let's use
mkdir repo cd repo git init
Add the remote to the git repository (ideally a GCP repository). For this example, let's use
git remote add google <url-to-remote-repository>
Create a script called
bqup.shthat follows the following template. For our example, our repository is dedicated to backups, so we just assume that our
HEADis the latest and just push gently to
#!/bin/bash <path-to-bqup> -p <project-id> -d <path-to-repo>/projects -fv >> <path-to-log-file> cd <path-to-repo> date > last-updated.log git add . git commit -m "Automated bqup" git push <remote> <branch>
Add this script to your crontab to run as frequently as your heart desires.
rm -rf dist python3 setup.py bdist_wheel
Test upload (optional, needs account)
twine upload -u thinkdatasci --repository-url https://test.pypi.org/legacy/ dist/*
twine upload -u thinkdatasci dist/*
bqup is maintained on a best effort basis:
- No amount of official time is currently being dedicated to the regular maintenance of this project.
- Thinking Machines does not make any guarantees about the quality of the software.
The official maintainers in charge of responding to issues and merging pull requests are:
A list is maintained for all external contributors who have submitted pull requests that were subsequently approved. Users are allowed and encouraged to fork the project and submit pull requests and issues. All contributions must adhere to these guidelines:
Thinking Machines reserves the rights to:
- refuse to resolve issues
- close issues without resolution
- request changes to pull requests
- reject pull requests outright