sppbackup - a consistent copy of the catalogue of sapupra, checked; one copy, or dated ones
sppbackup
[-v] [-k COUNT] [-D FILE]
[DIRECTORY]
sppbackup -h|-V
sppbackup copies the catalogue with the command .backup of sqlite3(1), which gives the catalogue as a reader sees it, whether the services run or not, and whatever the log of the database holds (a plain cp(1) of the file would give an old catalogue while the worker runs). The copy is made under a temporary name, put back in the usual journal mode of a file (it leaves no -wal and -shm file beside it), checked with PRAGMA integrity_check and refused if it is empty, and only then given its name: a copy that was being written, or that failed, is never found under the name of a good one.
By default there is one copy, catalogue-backup.db, which each run replaces. With -k more than 0 the copies are dated, to the second (a person may make more than one in a day): catalogue-backup-YYYY-MM-DD-HHMMSS.db, the last COUNT of them kept, the older ones removed, and catalogue-backup.db is a link to the newest, so that a command can name the copy without the date. Only the files named like a dated copy are removed: the others in the directory are not touched, and the dated copies that an earlier run left are neither removed by a run without -k nor counted by it.
It is made to be run by cron or by a timer, as the account that owns the database (sapupra), and says nothing when it succeeds, since cron mails what a job writes. What goes wrong is written on the standard error, which cron mails to the owner of the crontab, and to the log of the system (facility user, tag sppbackup), which is read when that mail is not; a success is logged too, one line, so that a run that did not happen is seen. The messages say what is wrong, and where: a directory on the way to the copies that the account cannot enter is named, with its owner and its mode, not reported as a file that cannot be opened.
It refuses to run as another account than the owner of the catalogue, root included: SQLite makes two files beside a database that it reads (the log and its index), and those made by another account are of no use to the worker. The copies are readable by all, like the catalogue (mode 0644; the directory 0755 when sppbackup makes it).
The options are
given before or after the directory. A value is given as
-k 3 or -k3 or --keep
3 or --keep=3; -- ends the
options.
-D, --database FILE
The catalogue to copy. Default: the file catalogue.db in the directory of the database of the installation (databasedir, written into the script when it is built: /var/db/sapupra or /var/lib/sapupra; the usage of the command shows it).
-k, --keep COUNT
0: one copy, replaced at each run; more than 0: dated copies, the last COUNT kept. Default: 0.
-v, --verbose
Says what was done on the standard output. Default: nothing is said unless it fails.
-h, --help
The usage, with the defaults.
-V, --version
The version.
DIRECTORY is where the copy goes. Default: a directory named backup beside the catalogue, which the command makes (the directory of the catalogue belongs to the account). Only the last directory of the path is made; the others must exist and be searchable by the account.
$ sudo -u
sapupra sppbackup --verbose
# a line for the crontab of the account sapupra, every day
at 10:25,
# one copy, always the last:
25 10 * * * /usr/local/sbin/sppbackup
# the same, keeping the last seven, dated:
25 10 * * * /usr/local/sbin/sppbackup --keep=7
databasedir/catalogue.db
The catalogue.
databasedir/backup
The copy, or the copies, by default.
|
0 |
A copy was made, checked and put in place. | ||
|
1 |
It was not: the message says why, and no copy is put under the name of a good one. The copies that were there are kept. | ||
|
2 |
A usage error. |
sppwork(8), sqlite3(1), crontab(5), Manual.org, section "Backing up the catalogue"; Design.org, section "The backup".
Péter Felecan, assisted by Claude Sonnet 5.5 (Anthropic).
Copyright (C) 2026 Péter Felecan. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.