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

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.

Solved

54 Replies

dev
MODERATOR

9 months ago

How are you storing your data?


dev
MODERATOR

9 months ago

I'm guessing some sort of sqlite file? If so you can just ssh into your service and retrieve the file


dev
MODERATOR

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


mjablonski
PRO

9 months ago

You'll need to mount a volume where you store the sqlite file. This way the database is persisted between deploys.


adam
MODERATOR

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.


naivedyam1
HOBBYOP

9 months ago

I can't see the sqlite file anywhere. Neither on github nor on Railway. Where can I see that?



adam
MODERATOR

9 months ago

Follow these docs, specifically the ssh section


dev
MODERATOR

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


naivedyam1
HOBBYOP

9 months ago

I am not sure


dev
MODERATOR

9 months ago

we can't really tell you where you're storing your data though only you'd know that


adam
MODERATOR

9 months ago

They said they use sqlite in the initial question


naivedyam1
HOBBYOP

9 months ago

But if I am storing it in memory then how is it working fine? It has been 2 days now


adam
MODERATOR

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


dev
MODERATOR

9 months ago

storing it in memory will work forever, until you redeploy


dev
MODERATOR

9 months ago

oh yea


naivedyam1
HOBBYOP

9 months ago

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


naivedyam1
HOBBYOP

9 months ago

I don't want them to be gone


naivedyam1
HOBBYOP

9 months ago

But even that is erasing on every redeployment


dev
MODERATOR

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


dev
MODERATOR

9 months ago

If you did store it in sqlite like you said then you just need to find your sqlite file


adam
MODERATOR

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


adam
MODERATOR

9 months ago

You mentioned you stored your data in a sqlite database. Let's start there


adam
MODERATOR

9 months ago

Use the Railway CLI from the link I sent to retrieve the sqlite file


adam
MODERATOR

9 months ago

Follow the docs I linked


naivedyam1
HOBBYOP

9 months 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

9 months ago

Ok


dev
MODERATOR

9 months ago

are you talking about sqlite3?


naivedyam1
HOBBYOP

9 months ago

yes


naivedyam1
HOBBYOP

9 months ago

1361793883729695000


dev
MODERATOR

9 months ago

you are storing it in a file


dev
MODERATOR

9 months ago

mycptrainer.db


naivedyam1
HOBBYOP

9 months ago

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


naivedyam1
HOBBYOP

9 months ago

but i cant see it anywhere


dev
MODERATOR

9 months ago

how are you looking at your files?


naivedyam1
HOBBYOP

9 months ago

on github/railway


dev
MODERATOR

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


dev
MODERATOR

9 months ago

on Railway, you should SSH into your service and go through your files, have you been doing that?


naivedyam1
HOBBYOP

9 months ago

going through the docs to do it now


dev
MODERATOR

9 months ago

perfect


naivedyam1
HOBBYOP

9 months ago

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


dev
MODERATOR

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)


dev
MODERATOR

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

  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


adam
MODERATOR

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.


naivedyam1
HOBBYOP

9 months ago

Thanks!


naivedyam1
HOBBYOP

9 months ago

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

1361803218442785000


adam
MODERATOR

9 months ago

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


naivedyam1
HOBBYOP

9 months ago

then how do i view the ssh without it


naivedyam1
HOBBYOP

9 months ago

???


naivedyam1
HOBBYOP

9 months ago

i got it


naivedyam1
HOBBYOP

9 months ago

got the database


naivedyam1
HOBBYOP

9 months ago

thanks a lot!


adam
MODERATOR

9 months ago

glad to hear it


adam
MODERATOR

9 months ago

!s


Status changed to Solved adam 9 months ago


Loading...