I can't view my database and it get's cleared every time I redeploy or update my code.
naivedyam1
HOBBYOP

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.

Solved

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


mjablonski
PRO

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.


naivedyam1
HOBBYOP

a year ago

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


naivedyam1
HOBBYOP

a year ago

I am not sure


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


naivedyam1
HOBBYOP

a year ago

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


naivedyam1
HOBBYOP

a year ago

So no way to retrieve it? I have like 250 users now


naivedyam1
HOBBYOP

a year ago

I don't want them to be gone


naivedyam1
HOBBYOP

a year ago

But even that is erasing on every redeployment


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


naivedyam1
HOBBYOP

a year ago

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.


naivedyam1
HOBBYOP

a year ago

Ok


a year ago

are you talking about sqlite3?


naivedyam1
HOBBYOP

a year ago

yes


naivedyam1
HOBBYOP

a year ago

1361793883729695000


a year ago

you are storing it in a file


a year ago

mycptrainer.db


naivedyam1
HOBBYOP

a year ago

i am doing this exactly so i feel a file called mycptrainer.db should be created


naivedyam1
HOBBYOP

a year ago

but i cant see it anywhere


a year ago

how are you looking at your files?


naivedyam1
HOBBYOP

a year ago

on github/railway


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?


naivedyam1
HOBBYOP

a year ago

going through the docs to do it now


a year ago

perfect


naivedyam1
HOBBYOP

a year ago

btw if it is a file why it is clearing on each instance of redeployment


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**

  1. SSH into your service

  2. Find your sqlite file, then retrieve its contents somehow - perhaps you can upload it somewhere via CLI or something

  3. Make sure you have the full database on your pc before continuing

*Re-adding your DB (assuming you want to keep using SQLite)

  1. insert the Filebrowser template into your project

  2. set USE_VOLUME_ROOT to 1

  3. Log into it and upload your db file

  4. Disconnect the volume

  5. Connect the volume to your service (you can mount it to something like /app/data or 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.


naivedyam1
HOBBYOP

a year ago

Thanks!


naivedyam1
HOBBYOP

a year ago

why this issue btw? I linked to my project but during ssh it says it isnt linked?

1361803218442785000


a year ago

You do not need the project, environment, and service flags in the ssh command


naivedyam1
HOBBYOP

a year ago

then how do i view the ssh without it


naivedyam1
HOBBYOP

a year ago

???


naivedyam1
HOBBYOP

a year ago

i got it


naivedyam1
HOBBYOP

a year ago

got the database


naivedyam1
HOBBYOP

a year ago

thanks a lot!


a year ago

glad to hear it


a year ago

!s


Status changed to Solved adam 11 months ago


Loading...