Regarding sqlite replication

断了今生、忘了曾经 提交于 2020-01-06 04:08:06

问题


I am working in sqlite db in my application using c++ linux. I have a requirement to replicate the sqlite db in another machine.

for this , since sqlite does not have replication machanism and also it does not have any network APIs , i want to read the sqlite db file using c++ fstream and create a new db file in the other machine.

i am struggling for a day.

Can anybody help me in this.

Below is the code :

 ifstream _fstream;
_fstream.open("Sourcefile",ios::in); 
 ofstream _ostream;
_ostream.open("ReplicatedFile",ios::out);
_ostream << _fstream;
_ostream.close();
_fstream.close();

回答1:


You might want to look at the built in SQLite Backup API which allows for online backup of the database. This could be used to create a form of replication, you would of course have to move the file to a remote location yourself (if desired). It is probably best to use the sqlite_backup_*() functions rather than directly accessing the file(s), since the sqlite functions will lock the database.




回答2:


I know the original post is old, but this may help others who have similar questions. I am not sure if this is what you want, but if you need to do the replication across multiple servers (distributed), Rqlite might be suited for you.

rqlite is a distributed relational database, which uses SQLite as its storage engine. rqlite uses Raft to achieve consensus across all the instances of the SQLite databases, ensuring that every change made to the system is made to a quorum of SQLite databases, or none at all.

you can read more here: http://www.philipotoole.com/replicating-sqlite-using-raft-consensus/

hope it helps,



来源:https://stackoverflow.com/questions/10793707/regarding-sqlite-replication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!