Is it possible to duplicate a Repl with all its data including Replit dabase's

Hey Replit Community,
I’m currently working on a Node.js project and wanted to know if it’s possible to somehow clone or duplicate this project. As far as I know, cloning can be achieved via uploading a repl into Github, then creating a blank Node.js repl and simply importing the code upon clicking the Import from Github button. But will this also clone data from Replit database? Otherwise, is there an alternative way?

Thanks in advance!

Visit your Repl’s cover page (the Repl’s link with ?v=1 on the end), then click “fork”. This won’t copy the database however and there is no official way to do that. However, there have been community attempts to do this.
image

4 Likes

Hey, @anon40284853 !
Thanks for your response! The fact that it’s not possible to clone the database’s data is disappointing, ngl. Do you know, is it possible to migrate the DB to a remote host? This way it’ll be accessible from cloned repl I guess

1 Like

It’s not possible to do so easily. If you have edit access to both Repls in question, then it can be done.
New Repl (One-Liner, works in Console and in main.py):

print(__import__("replit").db.db_url)

Copy the URL that outputs, then do this in the Old Repl (Multi-Line, but should work in both as well):

new=typeof(db:=__import__("replit").db)("URL_FROM_NEW_REPL_HERE")
for k in db: new[k]=db[k]

As long as your DB doesn’t have any bad keys, this should work.

Note: I minimized the above code quite a bit, if you’d like to see un-minimized code, I’ll be happy to oblige.

4 Likes

Thanks for code @Firepup650 ! Could you please share a code to achieve the same result but in Node.js (JavaScript code I mean)?

Thanks in advance!

1 Like

I made a little library some time ago that you could try:
By the way, you can just use the shell to get the database URL since it’s an environment variable.
Shell:

echo $REPLIT_DB_URL;

index.js:

const db = require("ez-repldb");
db.import("<insert REPLIT_DB_URL here>");

It might not be functional, I haven’t checked it in quite a while and I might have left it in a partially working state. :man_shrugging:

Essentially, all that does is something like this (but from scratch using fetch requests rather than Replit’s library):

const Client = require("@replit/database");

const new_db = new Client();
const old_db = new Client("<insert REPLIT_DB_URL here>");

old_db.getAll()
	.then((db) => {
		for (const key in db) {
			new_db.set(key, db[key]);
		}
	});
2 Likes

@MattDESTROYER Thanks very much for sharing the code! I’ll try that!

2 Likes