gopkg.in/dedis/onet.v2@v2.0.0-20181115163211-c8f3724038a7/Database-backup-and-recovery.md (about)

     1  Navigation: [DEDIS](https://github.com/dedis/doc/tree/master/README.md) ::
     2  [Onet](README.md) ::
     3  Database Backup and Recovery
     4  
     5  # Database Backup and Recovery
     6  
     7  Users of ONet have the option to make use of its built-in database.
     8  
     9  We use [bbolt](https://github.com/coreos/bbolt), which supports "fully
    10  serializable ACID transactions" to ensure data integrity for ONet users. Users
    11  should be able to do the following:
    12  
    13  - Backup data while ONet is running
    14  - Recovery from a backup in case of data corruption
    15  
    16  # Backup
    17  Users are recommend to perform frequent backups such that data can be recovered
    18  if ONet nodes fail. ONet stores all of its data in the context folder, specified
    19  by `$CONODE_SERVICE_PATH`. If unset, it defaults to
    20  - `~/Library/conode/Services` on macOS,
    21  - `$HOME\AppData\Local\Conode` on Windows, or
    22  - `~/.local/share/conode` on other Unix/Linux.
    23  
    24  Hence, to backup, it is recommended to use a standard backup tool, such as
    25  rsync, to copy the folder to a different physical location periodically.
    26  The database keeps a transaction log.
    27  So performing backups in the middle of a transaction should not be a problem.
    28  However, it is still recommended to check the data integrity of the backed-up file
    29  using the bbolt CLI, i.e. `bolt check database_name.db`.
    30  
    31  To install the bbolt CLI, see [Bolt Installation](https://github.com/coreos/bbolt#installing).
    32  
    33  # Recovery
    34  
    35  A data corruption is easy to detect as ONet nodes would crash when reading from
    36  a corrupted database, at startup or during operation. Concretely, the bbolt
    37  library would panic, e.g.
    38  [here](https://github.com/coreos/bbolt/blob/386b851495d42c4e02908838373a06d0a533e170/freelist.go#L237).
    39  This behavior is produced by writing a few blocks on random data using `dd` to
    40  the database.
    41  
    42  In case of data corruption, the database must be restored from a backup by
    43  simply copying the backup copy to the context directory, and then starting the
    44  conode again. It is the user's responsibility to make sure that the data is up
    45  to date, e.g. by reading the latest data from running ONet nodes.
    46  
    47  # Interacting with the database
    48  
    49  The primary and recommended methods to interact with the database is
    50  [`Load`](https://godoc.org/github.com/dedis/onet#Context.Load) and
    51  [`Save`](https://godoc.org/github.com/dedis/onet#Context.Save). If more control
    52  on the database is needed, then we can ask the context to return a database
    53  handler and bucket name using the function
    54  [`GetAdditionalBucket`](https://godoc.org/github.com/dedis/onet#Context.GetAdditionalBucket).
    55  All the [bbolt functions](https://godoc.org/github.com/coreos/bbolt) can be used
    56  with the database handler. However, the user should avoid creating new buckets
    57  using the bbolt functions and only use `GetAdditionalBucket` to avoid bucket
    58  name conflicts.