Disk ARchive  2.5.7
Full featured and portable backup and archiving tool
database.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 
27 #ifndef DATABASE_HPP
28 #define DATABASE_HPP
29 
30 #include "../my_config.h"
31 
32 #include <list>
33 
34 #include "archive.hpp"
35 #include "generic_file.hpp"
36 #include "data_tree.hpp"
37 #include "storage.hpp"
38 #include "database_options.hpp"
39 #include "on_pool.hpp"
40 
41 namespace libdar
42 {
44 
49  class database : public on_pool
50  {
51  public:
53  database();
54 
56 
60  database(user_interaction & dialog, const std::string & base, const database_open_options & opt);
61 
63  ~database();
64 
66 
71  void dump(user_interaction & dialog, const std::string & filename, const database_dump_options & opt) const;
72 
73  // SETTINGS
74 
76 
82  void add_archive(const archive & arch, const std::string & chemin, const std::string & basename, const database_add_options & opt);
83 
85 
92  void remove_archive(archive_num min, archive_num max, const database_remove_options & opt);
93 
95 
99  void set_permutation(archive_num src, archive_num dst);
100 
102 
107  void change_name(archive_num num, const std::string & basename, const database_change_basename_options &opt);
108 
110 
115  void set_path(archive_num num, const std::string & chemin, const database_change_path_options & opt);
116 
118 
124  void set_options(const std::vector<std::string> &opt) { options_to_dar = opt; };
125 
127 
131  void set_dar_path(const std::string & chemin) { dar_path = chemin; };
132 
133 
134  // "GETTINGS"
135 
137 
139  void show_contents(user_interaction & dialog) const; // displays all archive information
140 
142  std::vector<std::string> get_options() const { return options_to_dar; }; // show option passed to dar
143 
145 
148  std::string get_dar_path() const { return dar_path; }; // show path to dar command
149 
151 
157  void show_files(user_interaction & dialog, archive_num num, const database_used_options & opt) const;
158 
160 
164  void show_version(user_interaction & dialog, path chemin) const;
165 
167 
170  void show_most_recent_stats(user_interaction & dialog) const;
171 
172  // "ACTIONS" (not available with partially extracted databases)
173 
175 
180  void restore(user_interaction & dialog,
181  const std::vector<std::string> & filename,
182  const database_restore_options & opt);
183 
185 
189  bool check_order(user_interaction & dialog) const
190  {
191  bool initial_warn = true;
192 
193  if(files == nullptr)
194  throw SRC_BUG;
195  if(check_order_asked)
196  return files->check_order(dialog, ".", initial_warn) && initial_warn;
197  else
198  return true;
199  }
200 
201 
202  private:
203 
205  struct archive_data
206  {
207  std::string chemin; //< path to the archive
208  std::string basename; //< basename of the archive
209  datetime root_last_mod; //< last modification date of the root directory
210  };
211 
212  std::vector<struct archive_data> coordinate; //< list of archive used to build the database
213  std::vector<std::string> options_to_dar; //< options to use when calling dar for restoration
214  std::string dar_path; //< path to dar
215  data_dir *files; //< structure containing files and their status in the set of archive used for that database (is set to nullptr in partial mode)
216  storage *data_files; //< when reading archive in partial mode, this is where is located the "not readed" part of the archive (is set to nullptr in partial-read-only mode)
217  bool check_order_asked; //< whether order check has been asked
218  unsigned char cur_db_version; //< current db version (for informational purposes)
219 
220  void build(user_interaction & dialog, generic_file & f, bool partial, bool read_only, unsigned char db_version); //< used by constructors
221  archive_num get_real_archive_num(archive_num num, bool revert) const;
222 
223  const datetime & get_root_last_mod(const archive_num & num) const;
224  };
225 
226 } // end of namespace
227 
228 #endif
database()
this constructor build an empty database
options for file "used" in archive
options for changing a given archive&#39;s path
options to add an archive to base
the archive class is defined in this module
void restore(user_interaction &dialog, const std::vector< std::string > &filename, const database_restore_options &opt)
restore files calling dar on the appropriated archive
the data_dir class inherits from data_tree and holds the directory tree&#39;s parent relationship ...
Definition: data_tree.hpp:159
std::vector< std::string > get_options() const
return the options used with dar for restoration
Definition: database.hpp:142
void change_name(archive_num num, const std::string &basename, const database_change_basename_options &opt)
change one&#39;s archive basename recorded in the database
void remove_archive(archive_num min, archive_num max, const database_remove_options &opt)
remove an archive from a database
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
void add_archive(const archive &arch, const std::string &chemin, const std::string &basename, const database_add_options &opt)
add an archive to the database
two classes used to store tree information in dar_manager databases
This is a pure virtual class that is used by libdar when interaction with the user is required...
contains a class that permits arbitrary large data storage
options for changing a given archive&#39;s basename
void show_contents(user_interaction &dialog) const
show the list of archive used to build the database
options to remove an archive from the base
void show_version(user_interaction &dialog, path chemin) const
list the archive where a give file is present
options to write a database to file
bool check_order(user_interaction &dialog, const path &current_path, bool &initial_warn) const
check date order between archives withing the database ; throw Erange if problem found with date orde...
the archive class realizes the most general operations on archives
Definition: archive.hpp:56
arbitrary large storage structure
Definition: storage.hpp:57
void show_files(user_interaction &dialog, archive_num num, const database_used_options &opt) const
list files which are present in a given archive
void dump(user_interaction &dialog, const std::string &filename, const database_dump_options &opt) const
write the database to a file (see database_header first)
~database()
database destructor (no implicit file saving)
bool check_order(user_interaction &dialog) const
check that all files&#39;s Data and EA are more recent when archive number grows within the database...
Definition: database.hpp:189
options for restoration from database
void set_dar_path(const std::string &chemin)
change the path to dar command
Definition: database.hpp:131
void show_most_recent_stats(user_interaction &dialog) const
compute some statistics about the location of most recent file versions
this is the interface class from which all other data transfer classes inherit
void set_permutation(archive_num src, archive_num dst)
change order of archive within the database
this is the base class of object that can be allocated on a memory pool
std::string get_dar_path() const
return the path for dar
Definition: database.hpp:148
this file holds the options for database operations
void set_options(const std::vector< std::string > &opt)
change the default options given to dar when performing restoration
Definition: database.hpp:124
the database class defines the dar_manager database
Definition: database.hpp:49
void set_path(archive_num num, const std::string &chemin, const database_change_path_options &opt)
change one&#39;s archive path recorded in the database
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
the class path is here to manipulate paths in the Unix notation: using&#39;/&#39;
Definition: path.hpp:50