SQLite » Historie » Version 1
  Jeremias Keihsler, 13.01.2017 18:27 
  
| 1 | 1 | Jeremias Keihsler | h1. SQLite  | 
|---|---|---|---|
| 2 | |||
| 3 | h2. Backup DB  | 
||
| 4 | |||
| 5 | While SQLite-DB consists of just one file, you shouldn't just copy the file. It might be corrupted by doing so.  | 
||
| 6 | |||
| 7 | If you want to copy the DB-file you might want to (taken from http://stuvel.eu/blog/55/safely-copy-a-sqlite-database)  | 
||
| 8 | <pre><code class="bash">  | 
||
| 9 | shell$ sqlite3 some.db  | 
||
| 10 | sqlite> begin immediate;  | 
||
| 11 | <press CTRL+Z>  | 
||
| 12 | shell$ cp some.db some.db.backup  | 
||
| 13 | shell$ exit  | 
||
| 14 | sqlite> rollback;  | 
||
| 15 | </code></pre>  | 
||
| 16 | |||
| 17 | the other way may be dumping the DB. This is easily done by  | 
||
| 18 | <pre><code class="bash">  | 
||
| 19 | sqlite3 sample.db .dump > sample.bak  | 
||
| 20 | </code></pre>  | 
||
| 21 | |||
| 22 | based on the rsnapshot-backup-script for postgresql following script might be invoked by rsnapshot  | 
||
| 23 | <pre>  | 
||
| 24 | ##############################################################################  | 
||
| 25 | # backup_sqlite.sh  | 
||
| 26 | #  | 
||
| 27 | # by Jeremias Keihsler <j@keihsler.com>  | 
||
| 28 | # http://www.keihsler.com/  | 
||
| 29 | #  | 
||
| 30 | # based on the backup_pgsql.sh script  | 
||
| 31 | # by Nathan Rosenquist <nathan@rsnapshot.org>  | 
||
| 32 | #  | 
||
| 33 | # This is a simple shell script to backup a SQLite database with rsnapshot.  | 
||
| 34 | #  | 
||
| 35 | # The assumption is that this will be invoked from rsnapshot and also that it  | 
||
| 36 | # will run unattended.  | 
||
| 37 | #  | 
||
| 38 | # This script simply needs to dump a file into the current working directory.  | 
||
| 39 | # rsnapshot handles everything else.  | 
||
| 40 | ##############################################################################  | 
||
| 41 | |||
| 42 | umask 0077  | 
||
| 43 | |||
| 44 | # backup the database  | 
||
| 45 | /usr/bin/sqlite3 /var/www/html/owncloud/data/owncloud.db .dump > owncloud_dumpall.sql  | 
||
| 46 | |||
| 47 | # make the backup readable only by root  | 
||
| 48 | /bin/chmod 600 owncloud_dumpall.sql  | 
||
| 49 | </pre>  |