Hey, i have a file containing data, such as users etc. When i deploy (from github) it all works fine, but any data added using the deployed site is reset back to the github version when redeployed. Is there any way to fix this?
By default, storage is ephemeral, meaning any data is wiped when a new machine starts back to its own image state. You need to attach a persistent volume: Fly Volumes overview · Fly Docs
i have now tried for ages, and it still does not work. I have created a volume, attached it to the machine, i have specified in the toml file the source and destination. i’ve also watched fly.io’s tutorial on youtube but nope. data still resets
Can you share the code of the toml and where you’re writing to? Most likely you’re writing to the relative path and not the absolute root path of your persistent volume.
i have a folder in the application directory named data, i want the contents of data to be saved so it does not reset everytime the app deploys.
this is the mouns section of the toml file:
[mount]
source = “nibudata”
destination = “/var/www/html/data”
snapshot_retention = 1
I don’t see anything weird, so it should work. Is that the correct path in your application code?
what you mean, like reading the file?
you have to define that path somewhere in your app code right?
the path i use in the file for reading the file is “/data/datafile.db”
if that is what you are referring too
Yep that’s the issue. Can you see how those two paths are completely different?
but how would i link to the one in “/var/www/html/data”? how do i go to that directory from root?
is it just: file is in: “/var/www/html/data/datafile.db”
Generally, it can be anywhere, I’d use /data
for the mount path and /data/yourdb.db
for your db path
I’ll try to change it to /data/datafile.db
so it should be:
[mount]
source = “nibudata”
destination = “/data”
snapshot_retention = 1
and i just access db file like /data/datafile.db?
That looks good.
/var/www/html
looks like an Apache httpd directory. If you want the database to be downloadable from the web, you can create a symbolic link from /var/www/html/datafile.db
to /data/datafile.db
. You will also need to enable Options +FollowSymLinks
.
i just tried the new path, and it still does not save not sure what i’m doing wrong. I have the toml set up as above, and i tried to add some data, refreshed and it was still there. Then i did a new deployment, and it was gone again do i need to change anything with the in code filepath? or should it work by doing “/data/datafile.db”?
Try deleting your volume and recreating it? That or your application path is still referencing another path. It should work if you have it properly configured.
not working, i checked in the command line window, and when checking the volume and seeing what its mounted on, it looks correct: /dev/vdc 997076 24 929060 1% /data
so just to be clear, if i was to write to the datafile.db. would i access it like “data/datafile.db” in the code? just like in my local machine? or somehow else. because that is what i do currently. but it resets with every deply
“data/datafile.db” and “/data/datafile.db” are not the same. You’re likely missing the prefix “/”
i tried that already, it just gives “GET https://appname.fly.dev/getdata 500 (Internal Server Error)”
Look at your logs for errors around that api endpoint.