15

So I am at the place where I lost all of my Strapi data after moving from local to remote host and deploying my Strapi through herokuapp.com

I am using Strapi in my personal NEXT.JS project.

Luckily my Strapi database wasn't so huge and all content-types were kept so I was able to recreate the database quite quick. Also this was just a personal project.

I am wondering though, if I decide to push Strapi to use in in more professional context and in real project – how do I move from local development to deployment without loosing all data?

Is there a way to export everything before deployment and then import it into the deployed CMS or how does this work?

Also – what if I want to do it the other way around? I will keep working on my app using my Strapi on Heroku but at some point I will want to replicate the CMS locally. Where is the data stored and how do it get access to it?

juliomalves
  • 42,130
  • 20
  • 150
  • 146
Adam Schwarcz
  • 437
  • 1
  • 4
  • 14
  • Have you solved this issue yet? I am also struggling with it – dulikkk Jun 08 '21 at 16:51
  • 1
    I'm using `sqlite` so I copy my `./tmp` folder. As for recreating the admin folder `$ npm build`. If you have a non-flat database it should have it's own import/export tools. – Jacksonkr Jul 07 '21 at 14:09
  • I came across this topic today, and realizing some are pointing out this [library](https://github.com/EdisonPeM/strapi-plugin-import-export-content#readme) (personally have not tried yet) – Tommy Leong Aug 30 '21 at 01:30
  • @TommyLeong to be honest what I did and how I managed to solve this issue is by setting up a mongo instance deployed on heroku and added all data manually again. Now this way the data lives in actual mongodb and is not stored locally… It was definitely a hassle but I was lucky to be working mainly on the front end with minimal dataset (in most cases just some placeholder data) so reproducing that didn’t take that much time – Adam Schwarcz Aug 30 '21 at 07:37
  • Thanks for sharing your approach. Yea, I think in your case you're lucky because of minimal dataset. Probably not very suitable in the use of Production environment – Tommy Leong Aug 30 '21 at 07:45

4 Answers4

4

You can do it via the CLI now, new from version 4.6. Strapi supports export, import, and transfer.

To create a tar of your data:

npm run strapi export --file my-strapi-export

To import data into your project:

npm run strapi import -f export_file.tar.gz

There are more options in the docs: https://docs.strapi.io/developer-docs/latest/developer-resources/data-management.html#export-data-using-the-cli-tool

With the new data export & import system, you can backup & restore your Strapi project data without acting manually and directly into the database.

More info: https://strapi.io/blog/announcing-strapi-v4.6

tdy
  • 36,675
  • 19
  • 86
  • 83
Wespen
  • 51
  • 5
1

From docs: "Strapi does not currently provide any tools for migrating or deploying your data changes between different environments (ie. from development to production). With the exception being the Content-Manager settings"

And there is no export/import content for now.

To export your data for example from the local environment to the production you have to handle:

  • content-types - Strapi store this stuff at files so version control will help
  • database data - you have to make database backup manually and then import data at the production server
  • static files - if you use Srapi to handle the static files you probably will have to copy them manually and import them to the production server or use version control for it (bad option). They are stored at app/public/uploads

I didn't tried this myself but it looks like a pretty tough task.

Conclusion: if it's OK for you to migrate only your content types, just put a git on your Strapi folder

Yauhen
  • 401
  • 6
  • 7
0

Keep in mind Heroku is in the middle of shutting down its free tier, so using another provider like railway.app or render.com might be a good idea.

Anyway: As Eugene already mentioned in his answer there are 3 types of data that might have to transmitted (content types, the actual database, and files).

After your first deployment to Heroku you should end up with all content types being there, but with an empty database and no files.

Following this guide you will create an own database while setting up your project where you can now either export and import your database from your local development environment (which you would have to do manually) or put in new data by hand. Sometimes this is even better since development environments tend to include a lot of "Lorem Ipsum" content for testing purposes.

Future deployments should not reset your database though but keep your data from that environment.

Finally there are the files which I would recommend to store on Cloudinary since it's free, and Strapi offers an easy-to-use plugin for it. Just create a free account on Cloudinary, install the plugin in your Strapi project, and set your ENV variables for your production environment within Heroku.

Froxx
  • 957
  • 4
  • 14
  • 27
0

I found this

Apparently they recently did a plugin tutorial that had to do with this issue. There is a plugin called strapi-plugin-import-export-content on git hub that might be able to help your issue.

git hub link

Wayne
  • 660
  • 6
  • 16