# Back-up SQLite Database

**URL:** <https://discourse.nodered.org/t/back-up-sqlite-database/42995>\
**Category:** General\
**Created:** [22 March 2021 11:21 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995 "2021-03-22T11:21:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dgillett](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dgillett](https://discourse.nodered.org/u/Dgillett)\
**Post date:** [22 March 2021 11:21 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/1 "2021-03-22T11:21:13Z")

</div>

Im working with Node-Red to send MQTT data to a SQLite database and Provide data in an organized manner.

My Question, Is their a way to Backup the SQLite database automatically from Node-Red or another way to do it. I'm trying to get away from manually having to do this.

---

<div class="post-metadata">

**Author:** ![Simon01011](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@Simon01011](https://discourse.nodered.org/u/Simon01011)\
**Post date:** [22 March 2021 12:19 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/2 "2021-03-22T12:19:06Z")

</div>

I'm using a simple script, executed with cron. See [Sqlite — Kanboard documentation](https://docs.kanboard.org/en/latest/admin_guide/sqlite.html)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [22 March 2021 14:45 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/3 "2021-03-22T14:45:52Z")

</div>

A SQLite db is just a file isn't it? So you can use your normal backup capabilities to do it.

For example, I have some BASH scripts that do daily, weekly, monthly backups of my whole node-red installation. Using links to keep the size to a minimum (and not backing up the node\_modules folders which are easily replaced with a `npm install`). These run on CRON schedules so that I don't have to think about them.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [22 March 2021 19:07 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/4 "2021-03-22T19:07:42Z")

</div>

Just copying the file won't work because the database index get corrupted.  
I'm using an exec node with the settings as show below. with the sqlite backup command.  
This will make a backup of the sqlite database. This will lock the sqlite dbase temporary to make a backup.  
You can trigger the exec node (daily) with the trigger node.

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27a88ef49f65fa46ad3d75a0abaeb9f087c26b1b.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [22 March 2021 22:15 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/5 "2021-03-22T22:15:26Z")

</div>

As always, a simple search gives most of the answer:

[How to backup sqlite database? - Stack Overflow](https://stackoverflow.com/questions/25675314/how-to-backup-sqlite-database)

[android - What is the best way to take backup of sqlite database? - Stack Overflow](https://stackoverflow.com/questions/56286308/what-is-the-best-way-to-take-backup-of-sqlite-database)

---

<div class="post-metadata">

**Author:** ![Dgillett](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dgillett](https://discourse.nodered.org/u/Dgillett)\
**Post date:** [23 March 2021 17:11 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/6 "2021-03-23T17:11:57Z")

</div>

The EXEC node is what I'm looking for. So I can back it up in the same directory fine, But can I use this to back it up using a mounted external usb drive.

I tried and the node keeps throwing an error. But backs up perfect within the same folder.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 March 2021 17:25 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/7 "2021-03-23T17:25:40Z")

</div>

Show us how you have configured the node and what the error is. Just saying that it throws the error gives us no clues at all.

---

<div class="post-metadata">

**Author:** ![Dgillett](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dgillett](https://discourse.nodered.org/u/Dgillett)\
**Post date:** [23 March 2021 17:33 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/8 "2021-03-23T17:33:46Z")

</div>

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10250cabe62bde21b9be70186e66fc8ff46bdeb2.png)

This is how I configured it, and the node gives an error when backing up to mounted drive.

It works fine when I use ".backup /tmp/sqlite.backup"

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 March 2021 17:37 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/9 "2021-03-23T17:37:10Z")

</div>

> [@Dgillett](#):
>
> the node gives an error

Does the command run in a terminal? If not then it won't run in node-red

If it does run in a terminal then you still haven't told us what the error is. If necessary Look on all the outputs of the exec node with debug nodes configured to show Complete Message.

---

<div class="post-metadata">

**Author:** ![Dgillett](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dgillett](https://discourse.nodered.org/u/Dgillett)\
**Post date:** [23 March 2021 17:48 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/10 "2021-03-23T17:48:50Z")

</div>

Command works in terminal and creates backup, but I was hoping the exec node automatically backs it up

Here is a picture of the error on node

 ![Capture2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/627215a6315af13c0be86eff007e1000265f2401.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 March 2021 17:52 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/11 "2021-03-23T17:52:00Z")

</div>

There is no point me making suggestions if you ignore them:

> [@Colin](#):
>
> Look on all the outputs of the exec node with debug nodes configured to show Complete Message.

---

<div class="post-metadata">

**Author:** ![Dgillett](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dgillett](https://discourse.nodered.org/u/Dgillett)\
**Post date:** [23 March 2021 17:56 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/12 "2021-03-23T17:56:03Z")

</div>

That helped, Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 March 2021 18:32 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/13 "2021-03-23T18:32:48Z")

</div>

For the benefit of anyone else finding this thread please tell us what the problem was.

---

<div class="post-metadata">

**Author:** ![Dgillett](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dgillett](https://discourse.nodered.org/u/Dgillett)\
**Post date:** [23 March 2021 19:33 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/14 "2021-03-23T19:33:45Z")

</div>

It was my bad, Im still relatively new to linux. Permissions problem within the folder.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 April 2021 19:34 UTC](https://discourse.nodered.org/t/back-up-sqlite-database/42995/15 "2021-04-22T19:34:20Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
