Database down via terminal

Published

Updated

Open an SSH tunnel to the fortrabbit environment, dump the database with mysqldump, and import the file into the local database with the mysql client.

Get ready

With the frbit CLI

# 01. Dump the remote database to {{app-env-id}}.sql.gz
$ frbit db pull {{app-env-id}}

# 02. Import to your local database
$ gunzip -c {{app-env-id}}.sql.gz | mysql -u{{local-db-user}} -p {{local-db-name}}
shell

frbit db pull runs mysqldump on the environment over SSH, with no tunnel and no MySQL password. It never touches the local database. --output sets another file or folder.

Without the frbit CLI

# Terminal window 1
ssh -N -L 13306:mysql:3306 {{app-env-id}}@ssh.{{region}}.frbit.app
# This has no output. Open a new terminal window next.
shell
# Terminal window 2
# 01. Create a dump from the remote database
mysqldump --set-gtid-purged=OFF --no-tablespaces -h127.0.0.1 -P13306 -u{{app-env-id}} -p {{app-env-id}} > fortrabbit-backup.sql

# 02. Import to your local database
mysql -u{{local-db-user}} -p {{local-db-name}} < fortrabbit-backup.sql
shell

Other development environments

Container-based setups need extra steps:

  • Docker: run the commands in the database container with docker exec -i {container} ….
  • DDEV: ddev import-db --file=fortrabbit-backup.sql imports the dump, ddev import-db --file={{app-env-id}}.sql.gz the one of frbit db pull. ddev auth ssh makes the SSH key available in the container, ddev ssh opens a shell in it.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗