a year 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
a year ago
How are you storing your data?
a year ago
I'm guessing some sort of sqlite file? If so you can just ssh into your service and retrieve the file
a year 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
a year ago
You'll need to mount a volume where you store the sqlite file. This way the database is persisted between deploys.
a year 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?
a year ago
Follow these docs, specifically the ssh section
a year ago
Do you know if it is an SQLite file though? if you're storing the sessions in memory then you might be cooked
a year ago
we can't really tell you where you're storing your data though only you'd know that
a year 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
a year 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
a year ago
storing it in memory will work forever, until you redeploy
a year ago
oh yea
a year 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
a year ago
If you did store it in sqlite like you said then you just need to find your sqlite file
a year 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
a year ago
You mentioned you stored your data in a sqlite database. Let's start there
a year ago
Use the Railway CLI from the link I sent to retrieve the sqlite file
a year 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.
a year ago
are you talking about sqlite3?
a year ago
you are storing it in a file
a year ago
mycptrainer.db
i am doing this exactly so i feel a file called mycptrainer.db should be created
a year ago
how are you looking at your files?
a year 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
a year ago
on Railway, you should SSH into your service and go through your files, have you been doing that?
a year ago
perfect
a year 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)
a year 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
a year 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?

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