user938363
user938363

Reputation: 10350

Script to safely backup sqlite3 database on ubuntu 12.04 sever

We want to run a cron job for safely backing up sqlite3 db on ubuntu 12.04 server. The database may be locked by other apps when performing backup and we need the solution to be safe with this situation. There is backup api and we are not sure how to use it. The solution should be able to backup the entire db or even better incrementally. What we plan to do is to backup into a file on the same server. We are looking for a script which can plug into cron scheduler with none or a little modification.

Upvotes: 3

Views: 2229

Answers (1)

CL.
CL.

Reputation: 180060

The backup API can be invoked with the .backup command of the sqlite3 command-line tool.

To wait for other apps to unlock the database, you have to set a timeout with the .timeout command:

sqlite3 my.db <<EOF
.timeout 20000
.backup backup.db
EOF

SQLite has no incremental backup functionality.

Upvotes: 7

Related Questions