Heroku deploy deletes server files automatically?
Asked Answered
H

3

9

I'm new to HEROKU APPS.

In my heroku app i have a problem. that is I'm using a php script to save data on server.

Example :

<?PHP

$file = "example.txt";

$data = "Something...";

file_put_contents($file,$data);

?>

This PHP script run successfully and save data perfectly.

But, when I deploy my APP to HEROKU to update -> in this precess example.txt file is automatically deleted.

Holbrooke answered 25/12, 2012 at 15:38 Comment(1)
You didn't ask a questions but you've made a statement. Accept what you experience, because there is nothing to fix. This is the intended behavior and Heroku documentation is clear about that.Fries
E
12

Heroku File Systems

Heroku behavior varies depending a little on the stack you use. With Bamboo, most of the file system is read-only. With Cedar, it is ephemeral.

In either case, the file systems are not shared between dynos, and should not be used for storage. To reliably store data server-side, you will need to use the database (perhaps storing your uploads as blobs), or as external assets on another host or service.

Erst answered 25/12, 2012 at 15:56 Comment(0)
S
3

Heroku does not supply hard disk space to persistent files between git pushes, you'll have to use something like Amazon S3 for file storage. That is why Heroku calls their filesystem Ephemeral filesystem. It was even read-only in earlier versions of the stack.

Heroku has a tutorial on it: Using AWS S3 to Store Static Assets and File Uploads

Soliloquize answered 25/12, 2012 at 15:44 Comment(5)
Femaref , HEROKU gives 200MB space with free of cost.Holbrooke
@user1882503: Yes, for your code. That is what is in your git repro If you commit new files into your tree, that's perfectly fine. If not, they are lost. Easy.Fries
@Fries do you know any way to get or retrieve those files before being deleted? Or is it even possible?Hieronymus
@Cell No, and this is likely why they worded it "ephemeral". But perhaps support can help you?Fries
Oh yeah i did it myself, just hop in heroku bash session & python manage.py dumpdata > whole.json && cat whole.json. Not sure about static assets i just had blog posts.Hieronymus
F
1

Please see the docs:

Ephemeral filesystem

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted.

So you can not save much with your Heroku dyno. Especially after you've pushed your new version, the dyno is restarted and the file-system is reset then.

You need to store files into a remote location then if they should survive the dyno reset.

Fries answered 25/12, 2012 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.