问题
I need to create a Java class that creates a backup of my database. My problem is, I don't know how to do this using a SQLite database. Can anyone show me how?
回答1:
If the database is reasonably small, you can just call BEGIN EXCLUSIVE TRANSACTION
to prevent other processes from modifying the database, then copy the database file, then ROLLBACK TRANSACTION
. If the file is huge, you'll have to use the online backup interface (if your Java bindings don't support it, use JNI).
Of course, if there's just your app using this database and you can be sure that nobody's going to modify the file while you're copying it, just go for it and copy.
回答2:
The easiest thing is to create a copy of the database file- assuming it is a disk-based DB.
来源:https://stackoverflow.com/questions/11245244/backup-sqlite-using-java