# libdar::database Class Reference
[API]

the database class defines the dar_manager database More...

`#include <database.hpp>`

List of all members.

## Public Member Functions
| database ()
| this constructor build an empty database
| database (user_interaction &dialog, const std::string &base, bool partial)
| this constructor reads database from a file
| ~database ()
| database destructor (no implicit file saving)
void | dump (user_interaction &dialog, const std::string &filename, bool overwrite) const
| write the database to a file (see database_header first)
void | add_archive (const archive &arch, const std::string &chemin, const std::string &basename)
| add an archive to the database
void | remove_archive (archive_num min, archive_num max)
| remove an archive from a database
void | set_permutation (archive_num src, archive_num dst)
| change order of archive within the database
void | change_name (archive_num num, const std::string &basename)
| change one's archive basename recorded in the database
void | set_path (archive_num num, const std::string &chemin)
| change one's archive path recorded in the database
void | set_options (const std::vector< std::string > &opt)
| change the default options given to dar when performing restoration
void | set_dar_path (const std::string &chemin)
| change the path to dar command
void | show_contents (user_interaction &dialog) const
| show the list of archive used to build the database
std::vector< std::string > | get_options () const
| return the options used with dar for restoration
std::string | get_dar_path () const
| return the path for dar
void | show_files (user_interaction &dialog, archive_num num) const
| list files which are present in a given archive
void | show_version (user_interaction &dialog, path chemin) const
| list the archive where a give file is present
void | show_most_recent_stats (user_interaction &dialog) const
| compute some statistics about the location of most recent file versions
void | restore (user_interaction &dialog, const std::vector< std::string > &filename, bool early_release, const std::vector< std::string > &extra_options_for_dar, const infinint &date=0)
| restore files calling dar on the appropriated archive

## Detailed Description

the database class defines the dar_manager database

all operations for a dar_manager database are defines through the use of this class interface. This class also defines internally the data structure of the database.

Definition at line 49 of file database.hpp.

## Constructor & Destructor Documentation

libdar::database::database | ( | user_interaction & | dialog,
|  | const std::string & | base,
|  | bool | partial |
| ) |  |  |

this constructor reads database from a file

Parameters:

  `[in]` | dialog | for user interaction
  `[in]` | base | database filename
  `[in]` | partial | set to true to only load an manipulate database header

Note:
  not all methods are available if the database is partially built from file (see bellow)

## Member Function Documentation

void libdar::database::add_archive | ( | const archive & | arch,
|  | const std::string & | chemin,
|  | const std::string & | basename |
| ) |  |  |

add an archive to the database

Parameters:

  `[in]` | arch | is the archive to add to the database (may be a partial archive)
  `[in]` | chemin | is the path to this archive to record in the database
  `[in]` | basename | is the archive's basename to record in the database

Note:
  this method is not available with partially extracted databases.

void libdar::database::change_name | ( | archive_num | num,
|  | const std::string & | basename |
| ) |  |  |

change one's archive basename recorded in the database

Parameters:

  `[in]` | num | is the archive index to rename
  `[in]` | basename | is the new basename to give to that archive

void libdar::database::dump | ( | user_interaction & | dialog,
|  | const std::string & | filename,
|  | bool | overwrite |
| ) |  |  | const

write the database to a file (see database_header first)

Parameters:

  `[in]` | dialog | for user interaction
  `[in]` | filename | name of file to save database to
  `[in]` | overwrite | whether we can overwrite the file if it already exists

std::string libdar::database::get_dar_path | ( |  | ) | const`[inline]`

return the path for dar

Returns:
  the path to dar used when restoring files

Note:
  empty string means that dar is taken from the PATH variable

Definition at line 141 of file database.hpp.

void libdar::database::remove_archive | ( | archive_num | min,
|  | archive_num | max |
| ) |  |  |

remove an archive from a database

Parameters:

  `[in]` | min | first archive index to remove
  `[in]` | max | last archive index to remove

Note:
  the archives which indexes are in the range [min-max] are removed. If you want to remove only one archive choose min equal to max.

  this method is not available with partially extracted databases.

void libdar::database::restore | ( | user_interaction & | dialog,
|  | const std::vector< std::string > & | filename,
|  | bool | early_release,
|  | const std::vector< std::string > & | extra_options_for_dar,
|  | const infinint & | date = `0` |
| ) |  |  |

restore files calling dar on the appropriated archive

Parameters:

  `[in,out]` | dialog | where to have user interaction
  `[in]` | filename | list of filename to restore
  `[in]` | early_release | if set to true release memory before calling dar, consequences is that many calls to the database are no more possible.
  `[in]` | extra_options_for_dar | list of options to pass to dar
  `[in]` | date | passed this date files are ignored. So you can restore files in the most recent state before a certain "date".

Note:
  if "date" is set to zero, the most recent state available is looked for.

  this method is not available with partially extracted databases.

  if early_release is true, free almost all memory allocated by the database before calling dar. drawback is that no more action is possible after this call (except destruction) if date is zero the most recent version is looked for, else the last version before (including) the given date is looked for

void libdar::database::set_dar_path | ( | const std::string & | chemin | ) | `[inline]`

change the path to dar command

Parameters:

  `[in]` | chemin | is the full path to dar (including dar filename) to use for restoration

Note:
  if set to an empty string the dar command found from the PATH will be used (if any)

Definition at line 123 of file database.hpp.

void libdar::database::set_options | ( | const std::vector< std::string > & | opt | ) | `[inline]`

change the default options given to dar when performing restoration

Parameters:

  `[in]` | opt | is a vector a arguments.

Note:
  Each element of the vector must match a single argument of the command line like for example "-R". Any leading or trailing space will make a different argument than the one without spaces (" -R" is different than "-R" for example).

Definition at line 117 of file database.hpp.

void libdar::database::set_path | ( | archive_num | num,
|  | const std::string & | chemin |
| ) |  |  |

change one's archive path recorded in the database

Parameters:

  `[in]` | num | is the archive index who's path to change
  `[in]` | chemin | is the new path to give to that archive

void libdar::database::set_permutation | ( | archive_num | src,
|  | archive_num | dst |
| ) |  |  |

change order of archive within the database

Parameters:

  `[in]` | src | archive index to move
  `[in]` | dst | archive index to move to

Note:
  this method is not available with partially extracted databases.

void libdar::database::show_contents | ( | user_interaction & | dialog | ) | const

show the list of archive used to build the database

Parameters:

  `[in,out]` | dialog | is the user_interaction to use to report the listing

void libdar::database::show_files | ( | user_interaction & | dialog,
|  | archive_num | num |
| ) |  |  | const

list files which are present in a given archive

Parameters:

  `[in,out]` | dialog | where to display listing to
  `[in]` | num | is the archive number to look at

Note:
  if "num" is set to zero all archive contents is listed

  this method is not available with partially extracted databases.

void libdar::database::show_most_recent_stats | ( | user_interaction & | dialog | ) | const

compute some statistics about the location of most recent file versions

Parameters:

  `[in]` | dialog | where to display the listing to

Note:
  this method is not available with partially extracted databases.

void libdar::database::show_version | ( | user_interaction & | dialog,
|  | path | chemin |
| ) |  |  | const

list the archive where a give file is present

Parameters:

  `[in,out]` | dialog | where to display the listing to
  `[in]` | chemin | path to the file to look for

Note:
  this method is not available with partially extracted databases.

The documentation for this class was generated from the following file:

- database.hpp