DatoCMS records/assets/model backup

Hi,

I’m trying to create a backup of my DatoCMS project with all of the records, models & blocks and assets.
I found the doc that talks about backup but when I ran this with my set-up I see that it only exports the data and not the models or assets. https://www.datocms.com/docs/import-and-export/export-data

So my 2 questions here:

  1. Is there any way I can achieve backup of all records, models/blocks and assets?
  2. Is it possible to specify environment name along with the siteClient connection. The doc does not mention this. If I do something like this, I get a 401 error:
    const client = new SiteClient({ apiToken: "api-token", environment: "sandbox-backup-test" } );
    Only this seems to work but I don’t want to connect to my primary env:
    const client = new SiteClient('api-token' )

We would like to have a backup of the entire project and not just the data. In case we want to set-up a new project, then the model backup would really help here.

Hello @persis.jerifa.nelson.david.gift.jebakuma and welcome to the community!

The issue is that the client used in that script is the legacy client, so the syntax to use a different environment should be:

const client = new SiteClient('YOUR_API_TOKEN', {
  environment: 'YOUR_ENVIRONMENT_NAME'
});

Also, you might be interested in checking out these plugins, that may help you with different ways of backing up your project:

Thank you for the quick response and for sharing this!

Yes it looks like the syntax you provided works for accessing a specific environment.

Regarding backups, the links you shared are great for data and asset level backups, but is there something similar for Model/block backups? If not, is this something I can achieve with this content management API: https://www.datocms.com/docs/content-management-api/resources/item-type/instances

@persis.jerifa.nelson.david.gift.jebakuma the environment backups also backup schema information (so model, block and field configurations) but if you want to export schema information, then the way to go would be through the CMA using that exact endpoint you sent :slight_smile:

Yes exactly, I would like to export the back-up of the schema on DatoCMS so I was looking for something more than an environment level backup. Thanks!

@m.finamor Another quick question and would be great if you could help us out,

So I see the code in the Project explorer plugin for assets loops over each asset and calls each asset endpoint to download the assets. This means if I have over 5k assets I would make 5k calls to download them! Doesn’t sound so good and if the backup is scheduled for every working day, this would mean around 100k calls per month just for the asset backup!

Is there a better way to handle this? Is there maybe an API that can download a group of assets at once so that we do not have to make these many calls?

@persis.jerifa.nelson.david.gift.jebakuma Since we don’t have a “Bulk download” request, there is no better way to do this i’m afraid, and in case of the 5k assets, downloading them every single day for a backup would generate a very high amount of traffic, and would probably make you go over your limit pretty quickly.
So downloading all assets everyday for the project as a backup might be a bit overkill, and will definitely make you climb up pretty fast on traffic and API usage

A better way to handle the backups daily, might be to download all records everyday (that takes a small amount of traffic/requests) and bi-monthly download assets as well

@m.finamor I see, but I’m not sure if bi-monthly backups are also an ideal way to go for us. Perhaps an incremental back could help us here. Is there something I could directly use from Dato for this? or would we have to handle this logic ourselves?

  1. Initially get all assets from Dato - I guess the content management API could help here.
  2. Get only assets which were uploaded/deleted from Dato (say from a particular date).

If the 2nd point here is something I can retrieve using some endpoint from Dato it would help us.
Kind of curious how asset backup is managed by others in the community since I don’t find much about it.

@persis.jerifa.nelson.david.gift.jebakuma

You can filter assets based on their createdAt and updatedAt fields and only return records that were created/updated after a cut-off date: Filtering uploads - DatoCMS Filtering uploads - DatoCMS
You can use those filters in the CMA as well, through the filter fields object: List all uploads - Upload - Content Management API

Thanks I will check this out.