9 months ago
Project ID: 90bf4136-5c81-4fdd-a601-06632470fc26
I built a python telegram both using sqlite for the database. I realized my mistake of not using a persistent database like Postgress SQL later on but it was too late. I already got around 100 users now. Now if I redeploy or do any change in my code I will lose my data base and the bot will stop messaging those people. There is no database file in my github. Nor I can see any created by railway. I don't know where is my data. Please help me recover my database so that I can make a backup I don't wanna lose it all.
54 Replies
9 months ago
How are you storing your data?
9 months ago
I'm guessing some sort of sqlite file? If so you can just ssh into your service and retrieve the file
9 months ago
that way you have all the database data and you can either move it to a persistent storage directory or port it over to a database like PG
9 months ago
You'll need to mount a volume where you store the sqlite file. This way the database is persisted between deploys.
9 months ago
Before you do that, you will need to follow Fragly's instructions to retrieve your database file so you don't lose data when you redeploy.
I can't see the sqlite file anywhere. Neither on github nor on Railway. Where can I see that?
9 months ago
Follow these docs, specifically the ssh section
9 months ago
Do you know if it is an SQLite file though? if you're storing the sessions in memory then you might be cooked
9 months ago
we can't really tell you where you're storing your data though only you'd know that
9 months ago
They said they use sqlite in the initial question
But if I am storing it in memory then how is it working fine? It has been 2 days now
9 months ago
So I'm leaning on that possibility. If they're storing anything in memory it will be gone on a restart without any way to retrieve the data
9 months ago
storing it in memory will work forever, until you redeploy
9 months ago
oh yea
9 months ago
if you did store it in memory then yea retrieval is impossible
though to be clear that's not a railway problem
even if you hosted this on your own machine, if you stored it in memory then retrieval would've never been possible
it's not really a limitation on Railway, it's just a limitation of computers
-# Technically it is retrievable but it's next to impossible, it's like reconstructing a dollar note that's been burned to ash, technically possible but not realistically doable
9 months ago
If you did store it in sqlite like you said then you just need to find your sqlite file
9 months ago
Let's simplify this a bit, I think we're going off on a bit of a tangent talking about possibilities that may not be the case
9 months ago
You mentioned you stored your data in a sqlite database. Let's start there
9 months ago
Use the Railway CLI from the link I sent to retrieve the sqlite file
9 months ago
Follow the docs I linked
I don't know if I "stored" it into sqlite. There is no persistent storage. I just used sqlite python library to deal with it.
9 months ago
are you talking about sqlite3?
9 months ago
you are storing it in a file
9 months ago
mycptrainer.db
i am doing this exactly so i feel a file called mycptrainer.db should be created
9 months ago
how are you looking at your files?
9 months ago
github would only hold your code it wouldn't hold the database, unless you're pushing it to github which you shouldn't be doing
9 months ago
on Railway, you should SSH into your service and go through your files, have you been doing that?
9 months ago
perfect
btw if it is a file why it is clearing on each instance of redeployment
9 months ago
Railway deployments deploy your code into a container which is a small virtual machine that's set up to run your code
that virtual machine is destroyed and recreated whenever you redeploy because each deployment needs to create a new virtual machine for your code to run in
that means anything stored on that machine is destroyed including all your files
the way you workaround this is by adding volumes to your service
volumes allow you to store data in a directory that'll never be removed (unless you remove it)
9 months ago
I'm gonna head to bed soon so I'll summarize what you'll need to do from here
** Retrieving your DB**
SSH into your service
Find your sqlite file, then retrieve its contents somehow - perhaps you can upload it somewhere via CLI or something
Make sure you have the full database on your pc before continuing
*Re-adding your DB (assuming you want to keep using SQLite)
insert the Filebrowser template into your project
set
USE_VOLUME_ROOTto1Log into it and upload your db file
Disconnect the volume
Connect the volume to your service (you can mount it to something like
/app/dataor whatever, update the sqlite3.connect path accordingly)
If you want to use something other than SQLite, which I'd recommend tbh, then you'll need to port it over to your chosen database, that's a bit more work so I can't explain that in text here
After that, confirm that everything is in working order, make sure the data does persist and everything to prevent a future situation like this
9 months ago
I'll be around if you need help once Fragly is gone, but please do read the docs and attempt to SSH into your deployment as a first step.
why this issue btw? I linked to my project but during ssh it says it isnt linked?

9 months ago
You do not need the project, environment, and service flags in the ssh command
9 months ago
glad to hear it
9 months ago
!s
Status changed to Solved adam • 9 months ago
