Created
August 29, 2018 10:43
-
-
Save rcrowe/e06c73c911d937d4e748609ad0958ebd to your computer and use it in GitHub Desktop.
Dump a copy of all databases in CockroachDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # --------- | |
| # Variables | |
| # --------- | |
| dbHost=$COCKROACH_HOST | |
| if [[ -z $dbHost ]]; then | |
| dbHost=localhost | |
| fi | |
| dbPort=$COCKROACH_PORT | |
| if [[ -z $dbPort ]]; then | |
| dbPort=26257 | |
| fi | |
| dbUser=$COCKROACH_USER | |
| if [[ -z $dbUser ]]; then | |
| dbUser=root | |
| fi | |
| timestamp=$(date +%Y-%M-%d_%T) | |
| # -------- | |
| # Commands | |
| # -------- | |
| # List of databases | |
| databasesCmd="psql | |
| -h ${dbHost} | |
| -p ${dbPort} | |
| -U ${dbUser} | |
| -d system | |
| -c \"SELECT datname FROM pg_database WHERE datistemplate = false AND datname != 'system'\" -A -t" | |
| eval $databasesCmd | while read db; do | |
| echo Backing up $db | |
| file=$db-$timestamp.sql.gz | |
| # Dump SQL to file | |
| cockroach dump --insecure $db | gzip > $file | |
| # Cleanup | |
| rm $file | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment