SQLite | Database | Backing Up and Deleting a Database
This page explains how to back up a database created with SQLite by copying the database file, and how to delete a database.
Backing Up a Database
SQLite creates one file for each database, and all information is stored in that file. Therefore, to back up a specific database, you can simply copy the file used by that database.
Now check it in practice. Suppose the myfriend.sqlite3 database has already been created, and connect to this database.
$ sqlite3 myfriend.sqlite3
SQLite version 3.19.3 2017-06-27 16:48:08
Enter ".help" for usage hints.
sqlite>
Run the .tables command to check the tables created in the database. A table named customer has been created.
$ sqlite3 myfriend.sqlite3
SQLite version 3.19.3 2017-06-27 16:48:08
Enter ".help" for usage hints.
sqlite> .tables
customer
sqlite>
Now disconnect from the database. Then copy the myfriend.sqlite3 file and save it under another name, myfriendbackup.sqlite3. The file name can be anything.
$ cp myfriend.sqlite3 myfriendbackup.sqlite3
This creates a database identical to the original database. Next, connect to the myfriendbackup.sqlite3 database created as the backup and run the .tables command to display the list of tables created in the database.
$ sqlite3 myfriendbackup.sqlite3
SQLite version 3.19.3 2017-06-27 16:48:08
Enter ".help" for usage hints.
sqlite> .tables
customer
sqlite>
You can confirm that the same table as in the original database exists. This was only a simple check, but it shows that the database has been duplicated. In SQLite, you can back up a database simply by copying the file that contains the database data.
In addition to this method, SQLite also provides backup and recovery using the .backup and .restore commands.
Deleting a Database
SQLite manages each database independently as a single file. To delete a database, delete the file that stores the database. There is nothing else you need to do in SQLite.