Automated backups

Is this currently possible for Professional accounts? I desperately want Dato to offer something to automate this.

Hello @corysimmons and welcome to the community!

A way we recommend of doing that, is through environment forks:
You can fork your main environment on a time frame (e.g: daily for daily backups), and in the case of an accidental deletion or a similar problem, you can simply promote that backup environment and restore the dashboard state of the previous day.

To automate this, you can simply combine some REST API calls into a script, and then run that script through a cronjob.

Here is an example using Netlify Scheduled functions (serverless functions that function as cronjobs)

import { schedule } from "@netlify/functions";
import { buildClient } from "@datocms/cma-client-node";

export const handler = schedule("@daily", async (event) => {
  const client = buildClient({
    apiToken: process.env.DATOCMS_FULLACCESS_TOKEN as string,
  });

  const environments = await client.environments.list();

  const mainEnvironment = environments.find(
    (environment) => environment.meta.primary
  );

  const previousUnusedDailyBackup = environments.find(
    (environment) =>
      environment.id.match("backup-daily") && !environment.meta.primary
  );

  if (previousUnusedDailyBackup) {
    await client.environments.destroy(previousUnusedDailyBackup.id);
  }

  await client.environments.fork(mainEnvironment!.id, {
    id: `backup-daily-${new Date().toISOString().split("T")[0]}`,
  });

  return {
    statusCode: 200,
  };
});

2 Likes

You can clone this project: Netlify App
But first you’ll need to activate the experimental “scheduled functions” feature: Scheduled Functions | Netlify Docs

The forked env thing is clever, but I’d really love to have some assurance the Dato team has my instance’s database backed up on your servers somewhere nice and safe.

Oh @corysimmons , sorry, i thought you meant backups for user errors or personal redundancy.

On our end we do have automatic backups with RPO every minute for disaster recovery. RTO instead it should be in 2-4 hours.

We have a bit more on this on our security page: DatoCMS Security