Restore my Information in Database

A little while ago, I accidently deleted my folder that had all of my information saved, and I tried to go down to the histroy part and restore it, but it said I haven’t made any changes in 7 minutes. Is there another way I can fix this?

1 Like

You can recreate the folder and files if you know the names of them, which will then let you roll back the history for those files.

3 Likes

After getting back your db, You may want to use replit db AND a back up database just incase you lose it again. It makes it easier so you dont have to go through this grueling process of just finding the name folder or remembering the folder.

sample code:

import json
import os
import replit

keys = replit.db.keys()

data = {}
for key in keys:
    data[key] = replit.db[key]

file_path = os.path.join(os.getcwd(), "database_backup.json")

with open(file_path, "w") as f:
    json.dump(data, f, indent=2)

save function:

import json
import os
import replit
#Basically if you do db['keykeykey'] = 1 and you run the programme
#It should get saved in both databases.


def save():
  keys = replit.db.keys()

  data = {}
  for key in keys:
    data[key] = replit.db[key]

  file_path = os.path.join(os.getcwd(), "database_backup.json")

  with open(file_path, "w") as f:
    json.dump(data, f, indent=2)

eg.
x = input('Oh enter a str')
db['save!'] = x
save()
1 Like