turso-cli icon indicating copy to clipboard operation
turso-cli copied to clipboard

Database backup and restore

Open penberg opened this issue 2 years ago • 12 comments

It's not necessarily clear to our users that we're doing backups automatically. Also, there's no way for them to restore from a backup either.

penberg avatar May 03 '23 07:05 penberg

If we need to restore a backup, can you contact support to have it done?

jetaggart avatar May 13 '23 05:05 jetaggart

@jetaggart Yes you can. You can either reach out to us on Discord.

penberg avatar May 13 '23 05:05 penberg

I want to get an SQLite file every 24 hours to perform analytics queries for BI dashboards.

jokull avatar May 19 '23 14:05 jokull

~Is there a way we can programmatically create a backup?~ ~(Or a way to visualize what backups you folks have created/how often those are created?)~

~From the CLI or/and endpoints?~

NVM, this should work, right?

turso db shell MY_DATABASE .dump > dumpfile.sql

fforres avatar Jul 12 '23 02:07 fforres

@fforres Yes, the dump should work fine. We do want to improve the developer experience, of course.

penberg avatar Jul 12 '23 09:07 penberg

Dump and load is mentioned in the reference documentation. And yes, we can definitely do better as @penberg says.

CodingDoug avatar Jul 12 '23 12:07 CodingDoug

In the documentation, I only found related commands to "load", but nothing about "dump" 🤔

Mentions of loading are here: https://docs.turso.tech/cli/db/create

--from-dump	Create the database from a local SQLite dump.
--from-dump-url	Create the database from a remote SQLite dump.

But there is nothing about how to "dump", move the data from the remote database to the local computer.

I found out that this worked for me to get a dump, it would be nice to have it documented I think!

turso db shell MY_DATABASE .dump > dumpfile.sql

Jolg42 avatar Jan 19 '24 14:01 Jolg42

Hey @Jolg42

I've added the load and dump examples to this page in the docs. It was left out in our recent docs update but now should be covered.

notrab avatar Jan 19 '24 15:01 notrab

That's super nice @notrab thanks!

Jolg42 avatar Jan 19 '24 16:01 Jolg42

Also, the platform API lets the user to upload a dump from an url, but does not offer a way to make a dump. Can this be added?

GustavoOS avatar Jun 20 '24 01:06 GustavoOS

Hey @GustavoOS

This currently is a database feature that isn't yet available through the Platform API. I'm not sure if it will be any time soon, we'd likely want to make it more robust. I will document the current behaviour in our new libsql docs though.

You should be able to do this:

const response = await fetch('https://your-db-url.turso.io/dump', {
  headers: {
    Authorization: `Bearer [DATABASE_OR_GROUP_TOKEN_HERE]`,
  },
});

if (response.ok) {
  const text = await response.text();

  return new Response(text);
}

notrab avatar Jun 20 '24 09:06 notrab

Good to know it is a mapped feature. But I tested it with a small database, and this was the response I got { "error": "Replicator error: Timeout performing handshake with primary" }

GustavoOS avatar Jun 20 '24 19:06 GustavoOS