dbutil(1) | Mail Avenger 0.8.5 | dbutil(1) |
dbutil - database utility
dbutil {-d | --dump} dbfile
dbutil {-q | --query} [-t] dbfile key
dbutil {-u | --update} [-n] dbfile key [value]
dbutil {-x | --delete} dbfile key
dbutil -t [date | [+|-]interval]
The dbutil program maintains a database of key-value pairs that can be queried and updated from the command line. For each such pair in the database, it also keeps an expiration time, so that unused entries can be purged from the database. dbutil must be given an option specifying in which mode to run the program. The following modes are available:
key value (expiration-time)
Ordinarily, this option overwrites any previous value in the database. If the -n option is supplied, dbutil will not overwrite a previously stored value in the database (and will not update the expiration time on the record). Exits 0 if the key was found, 1 if -n was specified and the key was already in the database, or 2 if there is a system error.
Where + means in the future, - means in the past, count is a number, and units is one of the following characters:
For example --expire=+36D means the record will be deleted in 36 days. If you always look up key with the command:
then the key will only expire if you do not look it up within 36 days.
Note that dbutil keeps a sorted list of the records by time of last access. Thus, purging old records is not an inherently expensive operation, and happens automatically whenever you modify the database.
#!/bin/sh -e rm -f x.db~ dbutil -Nu x.db~ key1 val1 dbutil -Nu x.db~ key2 val2 # ... dbutil -Nu x.db~ keyn valn dbutil -u @ @ mv -f x.db~ x.db
Note that -t can also be combined with the --query option, in which case it causes dbutil to print the expiration time of the key, rather than its value.
dbutil attempts to minimize the damage from an inopportune crash by flushing the database file to disk whenever it is modified. However, there is still a small window in which your database can be irrevocably corrupted. This may be alright if you are just using the database to store "soft state".
If you want the database to be recoverable under any circumstances, you must use write-ahead logging, in which case dbutil needs to keep a directory with database logs, not just a single database file. The following option specifies where to keep the log files. It must be used in conjunction with the other options for each mode except -t:
The Mail Avenger home page: <http://www.mailavenger.org/>.
If you do not use the --dbhome option or DB_HOME environment variable and your machine crashes at the wrong time, you can lose your whole database.
The --dbhome may or may not work if the directory is stored on NFS; it depends on the NFS implementation.
If you access the database from multiple machines simultaneously, you will likely corrupt the database. Accessing from multiple processes on one machine is fine, because dbutil does locking.
If you ever access the same database file with and without the --dbhome option (or DB_HOME), you will probably irrevocably trash it. For that reason, databases with relative pathnames are actually stored in the log directory.
David Mazieres
2018-10-09 | Mail Avenger 0.8.5 |