# SQLite backup

**URL:** https://discourse.julialang.org/t/sqlite-backup/88654
**Category:** General Usage
**Tags:** sqlite
**Created:** [October 13, 2022, 11:29am UTC](https://discourse.julialang.org/t/sqlite-backup/88654 "2022-10-13T11:29:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![sransome](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sransome/32/29810_2.png) [@sransome](https://discourse.julialang.org/u/sransome)
#### Post date: [October 13, 2022, 11:29am UTC](https://discourse.julialang.org/t/sqlite-backup/88654/1 "2022-10-13T11:29:51Z")

</div>

Hi,

Is there a way of using sqlite.jl to execute the API commands like  
sqlite3\_backup\_init() ?

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [October 13, 2022, 1:14pm UTC](https://discourse.julialang.org/t/sqlite-backup/88654/2 "2022-10-13T13:14:36Z")

</div>

It seems so, I don’t know if it’s exported, or then how to access it, don’t know too much about this/SQLite:

> <https://github.com/JuliaDatabases/SQLite.jl/blob/master/src/capi.jl#L1803>

---

<div class="post-metadata">

### Author: ![sransome](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sransome/32/29810_2.png) [@sransome](https://discourse.julialang.org/u/sransome)
#### Post date: [October 15, 2022, 2:54am UTC](https://discourse.julialang.org/t/sqlite-backup/88654/3 "2022-10-15T02:54:55Z")

</div>

Thanks Palli. I’m sure someone can point me in the right direction.

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [October 17, 2022, 10:45am UTC](https://discourse.julialang.org/t/sqlite-backup/88654/4 "2022-10-17T10:45:27Z")

</div>

Well I thought I did already.

Since I found function sqlite3\_backup\_init there I thought it might be useful, i.e. you could call it, but that doesn’t seem to be the case.

But I was maybe helpful in (indirectly) pointing out you can call any C function, in general, with `@ccall` e.g. that one. To do that you could copy that function and make your own, or just use its contents.

But why can’t you call it, in the wrapper:

```julia
julia> SQLite.C.sqlite3_expanded_sql
ERROR: UndefVarError: C not defined

```

First of, the C module, and capi.jl file isn’t define in the last version of SQLite.jl, only on its master branch, so for any change (right now) you would have to do:

```julia
(@v1.8) pkg> add SQLite#master

```

It could be this capability is just in development, I thought the function might be there for SQLite itself to use (but it’s not used), or then for the user to use it by calling it, but I don’t think you can, since it isn’t exported.

Note, maybe the function was never meant to be used, I see it’s just one of many that were simply auto-generated:

> <https://github.com/JuliaDatabases/SQLite.jl/pull/296>
>
> A first step of https://github.com/JuliaDatabases/SQLite.jl/pull/295
> 
> 1. Use C…lang.jl to generate C bindings automatically
> 2. Use WeakKeyDict to record prepared statements of a DB
> 3. Upgrade Julia version requirement to 1.6
> 
> All tests pass locally.

The SQLite.jl file does:

```julia
include("capi.jl")

import .C

[..]

const DBHandle = Ptr{C.sqlite3}

```

I.e. it can refer to the C module, as there C.sqlite3, and could call the function you want. Often (as with Base) you can call functions even if they are not exported (but then maybe you shouldn’t, i.e. they are not part of the documented API). I thought that might be the case here but just don’t see how. I think `import .` means you can’t use what comes after the period, here C [module].

---

<div class="post-metadata">

### Author: ![sransome](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sransome/32/29810_2.png) [@sransome](https://discourse.julialang.org/u/sransome)
#### Post date: [October 19, 2022, 1:29am UTC](https://discourse.julialang.org/t/sqlite-backup/88654/5 "2022-10-19T01:29:06Z")

</div>

Thanks Palli,

I think I understand you. This is all beyond my skill level so unless someone can address the questions you raised, I’m at a dead end.

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [October 19, 2022, 2:33pm UTC](https://discourse.julialang.org/t/sqlite-backup/88654/6 "2022-10-19T14:33:29Z")

</div>

If you simply want to do a backup you don’t need to do it from Julia. I see here:

[https://docs.kanboard.org/en/1.2.21/admin\_guide/sqlite.html](https://docs.kanboard.org/en/1.2.21/admin_guide/sqlite.html)

> Technically, the database is just a single file located inside the directory `data` and named `db.sqlite`.
> 
> ## Export/Backup
> 
> ### Command line
> 
> Doing a backup is very easy, just copy the file `data/db.sqlite` somewhere else **when nobody use the software**.
> 
> If you want to do a backup while users are connected, you can use `sqlite3` to create the backup.

I put in the bold, with SQLite, as with other databases (e.g. PostgreSQL), it’s very dangerous to take a file-backup of you database (but not when you’ve shut it off for sure, meaning in case of SQLIte, your program using it).

I know PostgreSQL well (and SQLite just in theory), and you have online backups. I wasn’t expecting it for an embedded database like SQLite. [If you have many users,] also consider a different database, e.g. PostgreSQL, and LibPQ.jl.

[https://www.sqlite.org/backup.html](https://www.sqlite.org/backup.html)
