Restore backup

Hi,

I saw that there was a tutorial on taking a backup of the site at https://www.datocms.com/docs/import-and-export/export-data

Is it possible to restore from this backup? I would like to be able to ensure that we can always restore to a previous version in case something went wrong. Is this possible?

Kind regards,
Glenn

@glenn.bostoen I guess you’ve seen the other half of the guide, but I’ll link it just in case: https://www.datocms.com/docs/import-and-export/importing-data

in the other half we show how to import data from an existing backup. If you save all the records, uploads, models and fields you should be always able to restore everything.

Soon we’ll launch out of beta the sandbox environments, and with that also a feature for automatic backups. If you want to have a look we can duplicate your project and enable the sandbox environments so that you can have a go!

1 Like

Yes, I would like that if possible?

Staging projectID: #25850
Production projectID: #25478

Don’t know if it’s proper to use for production purposes already?
kind regards,
Glenn

Hello,

Any news on the restore backup feature ? would be really useful for my project

Kind regards,
Idir

Hey @idir.alileche

If you have an external backup, you can use our CMA to map it back into your project, and if you have a forked environment from the environment you deleted something, you can use it to transfer back the data through the CMA, or just promote the environment all together.

If you do not have any form of backup:

Unfortunately the backup on our end is reserved only for internal disaster recovery, as a means of recovering data from user mistakes, we recommend using a forked environment as a backup, allowing for the data to always be preserved.

We have some plugins in the marketplace that help you do this like this one: Automatic environment backups - Plugins — DatoCMS

That forks weekly and daily the main environment into two distinct backup sandboxes that can be promoted (or just accessed for reference) in case of user error.

We also have a plugin that sends deleted records to a bin, where they can be restored with a single click in case of user error: Record bin - Plugins — DatoCMS

Additionally you can also externally export your whole dashboard (all assets + records) by running this simple script: Exporting data and backups — DatoCMS

Hello @m.finamor

thank you for your reply.

let me explain my issue in more details, we have two different DATO projects, due to security restrictions, one for production and one for staging.
the thing is the contents in the production project is more up to date, so i would like to export all the schemes and contents and import them in a new env in our staging project.

is there any way to do this ? as i saw there was a feature in beta in the reply from mat_jack1

Thanks again

@idir.alileche you can do that with schema (models and fields) by following this: Keeping multiple DatoCMS projects in sync — DatoCMS

However, for content, we usually advise against transferring content between project, as it requires some scripting work to be done, to map the content of one project to another.

So, for schema, the way to go would be to use the tutorial above, but for content, using the REST API to fetch, then create records in the new project through a script is the only way to go unfortunately :frowning:

And just to clarify, @idir.alileche, you can have both prod and staging as different environments within the same project. That way it should be easier to clone the primary to a new sandbox any time you need it, or to promote a sandbox to primary if you need to “restore” an old backup.

You can also assign permissions to keep some users only on primary or only on sandboxes: Project collaborators, roles and permissions — DatoCMS

I still don’t know that I have a clear picture on how to restore a backup. The linked post: Import and export content - Importing data from external sources - DatoCMS Docs seems to show how to create new records in your environment, but does not talk about having a complete dump of records, as shown here and then restoring that into production.

So I’m left wondering what the proper way to achieve this is. Do I have to clone the primary environment, write a script that compares my backup file to the cloned environment, noting what records to modify, create or delete and then write code to do that? That all seems fairly complicated to just restore a backup, is there a better way to achieve this that I’m missing? Can I just fully restore my backup content into an empty environment and then promote that?

If I am trying to create records that reference each other, how does that work? If an Article object has a related field, let’s say Categories, do I have to write my script in such a way that I create the categories first? So it would matter exactly how my data in the json file was structured or I’d have to make multiple passes to create certain objects first?

This is where I’m getting confused and thinking that surely there is a better way to restore from one of these backup files that you show us how to create.

Thanks,
Bryan

@b.wyman it depends on what you’re trying to restore. If you make regular backups (like using this plugin, you can make nightlies: Automatic environment backups - Plugins — DatoCMS), then the easiest thing to do is to just promote one of the backup environments. That would be a “full” restore from that environment, meaning it would overwrite whatever was added to prod since that environment was initially made. You’d lose a day’s worth of content, yes, but the “restore” process itself would only take a second, since all you’re doing is marking one of the backups as the new primary env.

If you don’t want that data loss, then yes, I’m afraid you’ll have to manually write the script, diff the contents, and copy things over manually, keeping track of relationships in the process. I believe you’d have to create all the entities first and then make a separate call to update them to restore the links to the other records/media.

The bottom of this page, last example, shows an image create prior to associating it with a record, for example: Import and export content - Importing data from external sources - DatoCMS Docs

Yeah, that means a lot of tedious scripting :frowning: It’s far from ideal, unfortunately. For most use cases, we suggest just using the environments instead and doing a full restore, because that’s much simpler. Sorry about that :frowning: