Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to backup and restore Fly.io Postgres DB #87

Closed
3 tasks
nelsonic opened this issue Jan 25, 2023 · 12 comments
Closed
3 tasks

How to backup and restore Fly.io Postgres DB #87

nelsonic opened this issue Jan 25, 2023 · 12 comments
Assignees
Labels
BLOCKED Core team's HIGHEST priority, blocking critical work bug chore priority-1 T2h technical

Comments

@nelsonic
Copy link
Member

We have a Database Error that is causing our MVP to fail catastrophically: dwyl/mvp#281
We need to:

  • backup the DB
  • run it on localhost and
  • determine how to resolve the issue.

Starting point: https://fly.io/docs/rails/the-basics/backup-and-restoring-data/

@nelsonic nelsonic added bug T2h chore priority-1 technical BLOCKED Core team's HIGHEST priority, blocking critical work labels Jan 25, 2023
@nelsonic nelsonic self-assigned this Jan 25, 2023
@nelsonic nelsonic changed the title How to backup and restore Fly.io DB How to backup and restore Fly.io Postgres DB Jan 25, 2023
@nelsonic
Copy link
Member Author

This guide only tells us how to backup/restore on Fly.io.
It doesn't give us a way to export the data off the platform. 💭

@nelsonic
Copy link
Member Author

Daily backup snapshots are not being created. 😢
Need to investigate why ... 🔍

@nelsonic
Copy link
Member Author

@nelsonic
Copy link
Member Author

Backups are working:

fly volumes snapshots list vol_2n0l9vlnypor635d

You should see something similar to:

Snapshots
ID                    	SIZE    	CREATED AT
vs_50bygMmomApnXf6wmL 	62392863	22 hours ago
vs_QnL5Q9ZlZ6mwyh7Dy0Y	60940180	1 day ago
vs_0w0ym5D9D61ngC91VVl	59556750	2 days ago
vs_zQenbPLJLM3YlcMNaDB	59471566	3 days ago
vs_7zQy75mamR4nNf950xk	59379026	4 days ago
vs_ywgVbONANRPxXCGX15M	61236290	5 days ago

@nelsonic
Copy link
Member Author

installing DBeaver to attempt to connect to the Postgres DB directly: https://dbeaver.io/download/

brew install --cask dbeaver-community

@nelsonic
Copy link
Member Author

Created a new cluster off the snapshot:

fly postgres create --snapshot-id vs_50bygMmomApnXf6wmL

Output:

? Choose an app name (leave blank to generate one): debugging-281
? Select Organization: dwyl-mvp (dwyl-mvp)
? Select region: London, United Kingdom (lhr)
? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
Creating postgres cluster in organization dwyl-mvp
Creating app...
Setting secrets on app debugging-281...
Restoring 1 of 1 machines with image flyio/postgres:14.4
Waiting for machine to start...
Machine 5683605ade058e is created
==> Monitoring health checks
  Waiting for 5683605ade058e to become healthy (started, 3/3)

Postgres cluster debugging-281 created
  Username:    postgres
  Password:    nHcQaJGbTfZCqFO
  Hostname:    debugging-281.internal
  Proxy port:  5432
  Postgres port:  5433
  Connection string: postgres://postgres:nHcQaJGbTfZCqFO@debugging-281.internal:5432

Save your credentials in a secure place -- you won't be able to see them again!

Connect to postgres
Any app within the dwyl-mvp organization can connect to this Postgres using the above connection string

@nelsonic
Copy link
Member Author

Connect to the DB locally:

flyctl postgres connect -a debugging-281

@nelsonic
Copy link
Member Author

Port forwarding:

flyctl proxy 5432 -a debugging-281

proxy works but cannot connect form DBeaver ...

image

image

reading: https://community.fly.io/t/connecting-to-fly-database-from-local-elixir-application/3231

@nelsonic
Copy link
Member Author

Working:

image

With the config:

image

and proxy running:

flyctl proxy 5434:5432 -a debugging-281

@nelsonic
Copy link
Member Author

Attach the mvp app to the debugging-281 DB and see if it works. ⏳

@nelsonic
Copy link
Member Author

https://fly.io/docs/postgres/managing/attach-detach/

flyctl postgres detach --app <app-name> <postgres-app-name>

e.g:

flyctl postgres detach --app mvp mvp-db

Prompt:

? Select the attachment that you would like to detach (Database will remain intact):   [Use arrows to move, type to filter]
> PG Database: mvp, PG User: mvp, Environment variable: DATABASE_URL

but get the error:

Error error running user-delete: 500: ERROR: role "mvp" cannot be dropped because some objects depend on it (SQLSTATE 2BP01)

@nelsonic
Copy link
Member Author

nelsonic commented May 5, 2024

Fly.io completely lost our data. Ref: dwyl/mvp#449 (comment) 🔥
So this issue is void. 😢

GOTO: #90 🧑‍💻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLOCKED Core team's HIGHEST priority, blocking critical work bug chore priority-1 T2h technical
Projects
Status: Done
Development

No branches or pull requests

1 participant