RethinkDB: Is there a way to clone a DB in the same cluster using GUI or rql?
You can copy data from one table to another via ReQL as follows:
r.table(destination).insert(r.table(source))
This can also be run in a loop over all tables in a given database:
r.db(source).tableList().forEach(function (t) {
return r.db(destination).table(t).insert(r.db(source).table(t));
})
Similarly, you can create a loop to recreate all tables:
r.db(source).tableList().forEach(function (t) {
return r.db(destination).tableCreate(t);
})
This version does not store custom primary key or durability settings, but you get the idea.
Finally, to clone secondary indexes
r.db(source).tableList().forEach(function (t) {
return r.db(source).table(t).indexStatus().map(function (idx) {
return r.db(destination).table(t).indexCreate(
idx('index'), idx('function'), {geo: idx('geo'), multi: idx('multi')});
});
})
For all of these requests, I recommend running them in node.js or with a Python or Ruby client. Running them in Data Explorer will most likely not work because it takes lengthy queries after something like a minute.
source to share
You can do this in ReQL:
r.dbCreate('my_db_cloned')
r.db('my_db').tableList().forEach(r.db('my_db_cloned').tableCreate(r.row))
r.db('my_db').tableList().forEach(r.db('my_db_cloned').table(r.row).insert(r.db('my_db').table(r.row)))
You will need to wait half a second between the second and third commands to make sure the tables are available before inserting them. (In the upcoming 1.16 release, there will be a command tableWait
to remove the guesswork.)
Note that this does not copy secondary indexes.
source to share
I had the same problem. So I built a command line tool using @ DanielMewes suggestion.
https://github.com/internalfx/thinker
Hope it helps, save me a lot of time.
source to share