Disk ARchive 2.8.0
Full featured and portable backup and archiving tool
i_database.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26
27#ifndef I_DATABASE_HPP
28#define I_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_dir.hpp"
37#include "storage.hpp"
38#include "mem_ui.hpp"
39#include "database_options.hpp"
40#include "database_archives.hpp"
41#include "database.hpp"
42#include "tools.hpp"
43#include "datetime.hpp"
44#include "archive_options.hpp"
45
46namespace libdar
47{
48
51
53
55 {
56 public:
58 i_database(const std::shared_ptr<user_interaction> & dialog);
59
61 i_database(const std::shared_ptr<user_interaction> & dialog,
62 const std::string & base,
63 const database_open_options & opt);
64
66 i_database(const i_database & ref) = delete;
67
69 i_database(i_database && ref) noexcept = delete;
70
72 i_database & operator = (const i_database & ref) = delete;
73
75 i_database & operator = (i_database && ref) noexcept = delete;
76
79
81 void dump(const std::string & filename, const database_dump_options & opt) const;
82
83 // SETTINGS
84
86 void add_archive(const archive & arch, const std::string & chemin, const std::string & basename, const database_add_options & opt);
87
90
93
95 void change_name(archive_num num, const std::string & basename, const database_change_basename_options &opt);
96
98 void set_path(archive_num num, const std::string & chemin, const database_change_path_options & opt);
99
101 void set_options(const std::vector<std::string> &opt) { options_to_dar = opt; };
102
104 void set_dar_path(const std::string & chemin) { dar_path = chemin; };
105
107 void set_compression(compression algozip) const { algo = algozip; };
108
110 void set_compression_level(U_I level) const { compr_level = level; };
111
113 //
114 // "GETTINGS"
115 //
116
119
121 std::vector<std::string> get_options() const { return options_to_dar; }; // show option passed to dar
122
124 std::string get_dar_path() const { return dar_path; }; // show path to dar command
125
127 compression get_compression() const { return algo; };
128
130 U_I get_compression_level() const { return compr_level; };
131
133 std::string get_database_version() const { return tools_uint2str(cur_db_version); };
134
137 void *context,
138 archive_num num,
139 const database_used_options & opt) const;
140
143 void *context,
144 path chemin) const;
145
148 void *context) const;
149
150 // "ACTIONS" (not available with partially extracted databases)
151
153 void restore(const std::vector<std::string> & filename,
154 const database_restore_options & opt);
155
157
158 void restore(const archive_options_read & read_options,
159 const path & fs_root,
160 archive_options_extract extract_options,
161 const database_restore_options & opt,
162 statistics* progressive_report);
163
165 bool check_order() const
166 {
167 bool initial_warn = true;
168
169 if(files == nullptr)
170 throw SRC_BUG;
172 return files->check_order(get_ui(), path("."), initial_warn) && initial_warn;
173 else
174 return true;
175 }
176
177
178 private:
179
182 {
183 std::string chemin;
184 std::string basename;
186 };
187
188 std::deque<struct archive_data> coordinate;
189 std::vector<std::string> options_to_dar;
190 std::string dar_path;
194 unsigned char cur_db_version;
196 mutable U_I compr_level;
197
198 void build(generic_file & f, bool partial, bool read_only, unsigned char db_version);
199 archive_num get_real_archive_num(archive_num num, bool revert) const;
200
201 const datetime & get_root_last_mod(const archive_num & num) const;
202 };
203
205
206} // end of namespace
207
208#endif
the archive class is defined in this module
this file contains a set of classes used to transmit options to archive operation
class archive_num stores the position of an archive inside a dar_manager database
Definition: archive_num.hpp:47
class holding optional parameters used to extract files from an existing archive
class holding optional parameters used to read an existing archive
the archive class realizes the most general operations on archives
Definition: archive.hpp:68
the data_dir class inherits from data_tree and holds the directory tree's parent relationship
Definition: data_dir.hpp:53
virtual bool check_order(user_interaction &dialog, const path &current_path, bool &initial_warn) const override
check date order between archives withing the database ; throw Erange if problem found with date orde...
the class i_database is the implementation of class database
Definition: i_database.hpp:55
data_dir * files
structure containing files and their status in the set of archive used for that database (is set to n...
Definition: i_database.hpp:191
compression algo
compression used/to use when writing down the base to file
Definition: i_database.hpp:195
bool check_order_asked
whether order check has been asked
Definition: i_database.hpp:193
std::string get_dar_path() const
returns the path for dar
Definition: i_database.hpp:124
compression get_compression() const
returns the compression algorithm used on filesystem
Definition: i_database.hpp:127
unsigned char cur_db_version
current db version (for informational purposes)
Definition: i_database.hpp:194
i_database(i_database &&ref) noexcept=delete
disabling move constructor
void build(generic_file &f, bool partial, bool read_only, unsigned char db_version)
used by constructors
std::vector< std::string > options_to_dar
options to use when calling dar for restoration
Definition: i_database.hpp:189
void remove_archive(archive_num min, archive_num max, const database_remove_options &opt)
remove an archive from a database
void set_permutation(archive_num src, archive_num dst)
change order of archive within the database
i_database & operator=(const i_database &ref)=delete
disabling assignement operator
void set_path(archive_num num, const std::string &chemin, const database_change_path_options &opt)
change one's archive path recorded in the database
void restore(const std::vector< std::string > &filename, const database_restore_options &opt)
restore files calling dar on the appropriated archive
void get_files(database_listing_show_files_callback callback, void *context, archive_num num, const database_used_options &opt) const
list files which are present in a given archive
bool check_order() const
check that all files's Data and EA are more recent when archive number grows within the database,...
Definition: i_database.hpp:165
void show_most_recent_stats(database_listing_statistics_callback callback, void *context) const
compute some statistics about the location of most recent file versions
storage * data_files
when reading archive in partial mode, this is where is located the "not readed" part of the archive (...
Definition: i_database.hpp:192
i_database(const i_database &ref)=delete
disabling copy constructor
std::string dar_path
path to dar
Definition: i_database.hpp:190
U_I compr_level
the compression level to use
Definition: i_database.hpp:196
i_database(const std::shared_ptr< user_interaction > &dialog, const std::string &base, const database_open_options &opt)
this constructor reads i_database from a file
U_I get_compression_level() const
returns the compression level used on file
Definition: i_database.hpp:130
std::deque< struct archive_data > coordinate
list of archive used to build the database
Definition: i_database.hpp:188
void set_compression_level(U_I level) const
change the compression level to use when storing base in file
Definition: i_database.hpp:110
~i_database()
i_database destructor (no implicit file saving)
void set_compression(compression algozip) const
change compression to use when storing base on file
Definition: i_database.hpp:107
database_archives_list get_contents() const
provides the list of archive used to build the database
std::vector< std::string > get_options() const
return the options used with dar for restoration
Definition: i_database.hpp:121
void restore(const archive_options_read &read_options, const path &fs_root, archive_options_extract extract_options, const database_restore_options &opt, statistics *progressive_report)
restore files calling libdar directly rather than spawning dar CLI and parsing options as CLI
void change_name(archive_num num, const std::string &basename, const database_change_basename_options &opt)
change one's archive basename recorded in the database
void get_version(database_listing_get_version_callback callback, void *context, path chemin) const
list the archive where a give file is present
void dump(const std::string &filename, const database_dump_options &opt) const
write the database to a file (see database_header first)
std::string get_database_version() const
return the database format version
Definition: i_database.hpp:133
void set_dar_path(const std::string &chemin)
change the path to dar command
Definition: i_database.hpp:104
i_database(const std::shared_ptr< user_interaction > &dialog)
this constructor build an empty database
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
void set_options(const std::vector< std::string > &opt)
change the default options given to dar when performing restoration
Definition: i_database.hpp:101
options to add an archive to base
options for changing a given archive's basename
options for changing a given archive's path
options to write a database to file
options to open a database
options to remove an archive from the base
options for restoration from database
options for file "used" in archive
stores time information
Definition: datetime.hpp:59
this is the interface class from which all other data transfer classes inherit
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:55
user_interaction & get_ui() const
get access to the user_interaction object
Definition: mem_ui.hpp:94
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:51
class used by libdar::archive class to give a summary of treated file during and after an operation
Definition: statistics.hpp:70
arbitrary large storage structure
Definition: storage.hpp:53
classes used to store directory tree information in dar_manager databases
this file holds the database class definition
this file stores the list of archives a database has been built from. it is part of the database head...
this file holds the options for database operations
this file contains the definition of class datetime that stores unix times in a portable way
class generic_file is defined here as well as class fichier
std::deque< database_archives > database_archives_list
list of archives found in a database
void(*)(void *context, const std::string &filename, bool available_data, bool available_ea) database_listing_show_files_callback
called by the database::get_files() routine
void(*)(void *context, U_I number, const infinint &data_count, const infinint &total_data, const infinint &ea_count, const infinint &total_ea) database_listing_statistics_callback
called with teh information of statistics for each archive in turn
void(*)(void *context, archive_num num, db_etat data_presence, bool has_data_date, datetime data, db_etat ea_presence, bool has_ea_date, datetime ea) database_listing_get_version_callback
called with the information of presence for an entry in archive number num
compression
the different compression algorithm available
Definition: compression.hpp:46
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
contains a class that permits arbitrary large data storage
holds the archive used to create the database
Definition: i_database.hpp:182
std::string chemin
path to the archive
Definition: i_database.hpp:183
datetime root_last_mod
last modification date of the root directory
Definition: i_database.hpp:185
std::string basename
basename of the archive
Definition: i_database.hpp:184
a set of general purpose routines