Skip to content

Data: the disk, SQLite, db, run and Backups

Where your App keeps its data so it survives every Deploy and every sleep, the SQLite database every App already has, and how to query it or run a script where the data is.

The disk

Every App has its own disk, mounted at /data (also in $BASEMODO_DATA). What your App writes there stays: through every Deploy, every sleep, every restart. Everything else on the machine is replaced at the next Deploy, so never keep data next to your code.

The database

Every App has a SQLite database at /data/app.db, also in $BASEMODO_DB. There is nothing to provision or connect to: your App opens the file, and the first to open it creates it. SQLite is fast, needs no server, and is plenty for small software.

Node (22 and later have SQLite built in):

import { DatabaseSync } from "node:sqlite";
const db = new DatabaseSync(process.env.BASEMODO_DB ?? "app.db");
db.exec("create table if not exists tasks (id integer primary key, title text, done integer default 0)");
const tasks = db.prepare("select * from tasks").all();

Python:

import os
import sqlite3
db = sqlite3.connect(os.environ.get("BASEMODO_DB", "app.db"))
db.execute("create table if not exists tasks (id integer primary key, title text)")

Falling back to a local file name, as above, lets the same code run on your computer. With Django, point DATABASES["default"]["NAME"] at os.environ.get("BASEMODO_DB").

Looking at it: basemodo db

Run SQL against an App's database from your terminal, or let your agent do it with the db tool:

Terminal window
basemodo db "select * from tasks order by id desc limit 10"
basemodo db "update tasks set done = 1 where id = 7"
basemodo db < fix-titles.sql

It prints a table (or JSON with --json). Several statements run in order and stop at the first error. If the App is asleep, it is woken first. See basemodo db.

Running a script: basemodo run

Run a one-off command inside the App's machine, where its disk, its database and its Secrets are: a migration, an import, a quick look around.

Terminal window
basemodo run "npm run migrate"
basemodo run python manage.py migrate
basemodo run -- ls -la /data

Its output comes back as it runs, and the command exits as the remote command did. It may run up to 60 seconds, or longer with --timeout (at most 15 minutes). See basemodo run.

Basemodo never runs migrations by itself when a Deploy starts: run them with basemodo run when you choose, so a bad migration never runs twice.

Backups: basemodo backup and basemodo restore

Basemodo backs every App's data up once a day: the database and every file on its disk, kept 7 days (30 on Pro and Workspace, see Plans). Take one yourself before something risky, then put the data back if it goes wrong:

Terminal window
basemodo backup # prints the Backup's id
basemodo run "npm run migrate"
basemodo backups # the App's Backups, newest first
basemodo restore <backup> # the data as it was when that Backup was taken

Restoring replaces everything written since the Backup; the Backup itself stays, and the App runs again afterwards. Your agent has the same backup, backups and restore tools. See basemodo backup and basemodo restore.

Downloading your data

The App's page on basemodo.com has Download the data: a .tar.gz of everything on its disk, with the database copied by SQLite's own online backup, so it is consistent even while the App writes to it. Open data/app.db with any SQLite tool.

Deleting an App

Deleting an App (on its page, by its Owner) stops it at once, and its address stops answering. Its last Backup is kept for 7 days (30 on Pro and Workspace): basemodo restore <backup> with the id the page shows brings the App back as it was. After that its data is gone for good and its address is free for someone else.