Next: , Previous: Packet I/O, Up: Command Reference


5.8 Database

mtn set domain name value
Associates the value value to name in domain domain. See Vars for more information.
mtn unset domain name
Deletes any value associated with name in domain. See Vars for more information.
mtn register_workspace [workspace_path]
Registers the given workspace from the current database, so that it will show up in the output of list databases (the database has to be in a managed location for this to work).

If no workspace_path is given, this command defaults to the current workspace.

mtn unregister_workspace [workspace_path]
Unregisters the given workspace from the current database, so that it will no longer show up in the output of list databases.

If no workspace_path is given, this command defaults to the current workspace.

mtn cleanup_workspace_list
Removes all invalid workspaces from the list of registered workspaces of the current database. A workspace is considered invalid if its path does either not contain an _MTN directory anymore or if the configured database for this workspace is a different one.
mtn db init --db=dbfile
This command initializes a new monotone database at dbfile.
mtn db info --db=dbfile
This command prints information about the monotone database dbfile, including its schema version and various table size statistics.
mtn db version --db=dbfile
This command prints out just the schema version of the monotone database dbfile.
mtn db dump --db=dbfile
This command dumps an SQL statement representing the entire state of dbfile to the standard output stream. It is a very low-level command, and produces the most “recoverable” dumps of your database possible. It is sometimes also useful when migrating databases between variants of the underlying SQLite database format.
mtn db load --db=dbfile
This command applies a raw SQL statement, read from the standard input stream, to the database dbfile. It is most useful when loading a database dumped with the dump command.

Note that when reloading a dumped database, the schema of the dumped database is included in the dump, so you should not try to init your database before a load.

mtn db migrate --db=dbfile
This command attempts to migrate the database dbfile to the newest schema known by the version of monotone you are currently running. If the migration fails, no changes should be made to the database.

If you have important information in your database, you should back up a copy of it before migrating, in case there is an untrapped error during migration.

mtn db check --db=dbfile
Monotone always works hard to verify the data it creates and accesses. For instance, if you have hard drive problems that corrupt data in monotone's database, and you attempt to retrieve this data, then monotone will notice the problem and stop, instead of silently giving you garbage data.

However, it's also nice to notice such problems early, and in rarely used parts of history, while you still have backups. That's what this command is for. It systematically checks the database dbfile to ensure that it is complete and consistent. The following problems are detected:

This command also verifies that the sha1 hash of every file, manifest, and revision is correct.

mtn db kill_rev_locally id
This command “kills”, i.e., deletes, a given revision, as well as any certs attached to it. It has an ugly name because it is a dangerous command; it permanently and irrevocably deletes historical information from your database. If you execute this command in a workspace, whose parent revision is the one you are about to delete, the killed revision is re-applied to this workspace which makes it possible for you to fix a problem and commit again later on easily. For this to work, the workspace may not have any changes and/or missing files.

There are a number of other caveats with this command:


mtn db kill_branch_certs_locally branch
This command “kills” a branch by deleting all branch certs with that branch name. You should consider carefully whether you want to use it, because it can irrevocably delete important information. It does not modify or delete any revisions or any of the other certificates on revisions in the branch; it simply removes the branch certificates matching the given branch name. Because of this, it can leave revisions without any branch certificate at all. As with db kill_rev_locally, it only deletes the information from your local database; if there are other databases that you sync with which have revisions in this branch, the branch certificates will reappear when you sync, unless the owners of those databases also delete those certificates locally.
mtn db kill_tag_locally tag
This command “kills” a tag by deleting all tag certs with that tag name. You should consider carefully whether you want to use it, because it can irrevocably delete important information. It does not modify or delete any revisions, or any of the other certificates on tagged revisions; it simply removes all tag certificates with the given name. As with db kill_rev_locally, it only deletes the information from your local database; if there are other databases that you sync with which have this tag, the tag certificates will reappear when you sync, unless the owners of those databases also delete those certificates locally.
mtn db execute sql-statement
This is a debugging command which executes sql-statement against your database, and prints any results of the expression in a tabular form. It can be used to investigate the state of your database, or help diagnose failures.