Disk ARchive  2.4.21
archive.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 ARCHIVE_HPP
28 #define ARCHIVE_HPP
29 
30 #include "../my_config.h"
31 #include <vector>
32 
33 #include "erreurs.hpp"
34 #include "path.hpp"
35 #include "scrambler.hpp"
36 #include "statistics.hpp"
37 #include "archive_options.hpp"
38 #include "escape.hpp"
39 #include "escape_catalogue.hpp"
40 #include "pile.hpp"
41 #include "list_entry.hpp"
42 
43 namespace libdar
44 {
45 
47 
52  class archive
53  {
54  public:
55 
57 
64  archive(user_interaction & dialog,
65  const path & chem,
66  const std::string & basename,
67  const std::string & extension,
68  const archive_options_read & options);
69 
70 
72 
91  archive(user_interaction & dialog,
92  const path & fs_root,
93  const path & sauv_path,
94  const std::string & filename,
95  const std::string & extension,
96  const archive_options_create & options,
97  statistics * progressive_report);
98 
99 
101 
108  archive(user_interaction & dialog,
109  const path &sauv_path,
110  archive *ref_arch,
111  const std::string & filename,
112  const std::string & extension,
113  const archive_options_isolate & options);
114 
115 
117 
132 
133  archive(user_interaction & dialog,
134  const path & sauv_path,
135  archive *ref_arch1,
136  const std::string & filename,
137  const std::string & extension,
138  const archive_options_merge & options,
139  statistics * progressive_report);
140 
142 
147 
148  archive(const archive & ref) : stack(ref.stack) { throw Efeature(dar_gettext("Archive copy constructor is not implemented")); };
149  archive & operator = (const archive & ref) { throw Efeature(dar_gettext("Archive assignment operator is not implemented")); };
150 
152  ~archive() { free(); };
153 
154 
156 
176  const path &fs_root,
177  const archive_options_extract & options,
178  statistics *progressive_report);
179 
183  void summary(user_interaction & dialog);
184 
185 
187 
196  void op_listing(user_interaction & dialog,
197  const archive_options_listing & options);
198 
200 
215  const path & fs_root,
216  const archive_options_diff & options,
217  statistics * progressive_report);
218 
219 
221 
242  const archive_options_test & options,
243  statistics * progressive_report);
244 
245 
247 
255  bool get_children_of(user_interaction & dialog,
256  const std::string & dir);
257 
267  const std::vector<list_entry> get_children_in_table(const std::string & dir) const;
268 
270  const entree_stats get_stats() const { if(cat == NULL) throw SRC_BUG; return cat->get_stats(); };
271 
274  void init_catalogue(user_interaction & dialog) const;
275 
277 
285  const catalogue & get_catalogue() const;
286 
288  const catalogue & get_catalogue(user_interaction & dialog) const;
289 
291 
298 
300 
302 
303  private:
304  enum operation { oper_create, oper_isolate, oper_merge };
305 
306  pile stack;
307  header_version ver;
308  catalogue *cat;
309  infinint local_cat_size;
310  path *local_path;
311  bool exploitable; //< is false if only the catalogue is available (for reference backup or isolation).
312  bool lax_read_mode; //< whether the archive has been openned in lax mode (unused for creation/merging/isolation)
313  bool sequential_read; //< whether the archive is read in sequential mode
314 
315  void free();
316  catalogue & get_cat() const { if(cat == NULL) throw SRC_BUG; else return *cat; };
317  const header_version & get_header() const { return ver; };
318  const path & get_path() { if(local_path == NULL) throw SRC_BUG; else return *local_path; };
319 
320  bool get_sar_param(infinint & sub_file_size, infinint & first_file_size, infinint & last_file_size,
321  infinint & total_file_number);
322  infinint get_level2_size();
323  infinint get_cat_size() const { return local_cat_size; };
324 
325  statistics op_create_in(user_interaction & dialog,
326  operation op,
327  const path & fs_root,
328  const path & sauv_path,
329  archive *ref_arch,
330  const mask & selection,
331  const mask & subtree,
332  const std::string & filename,
333  const std::string & extension,
334  bool allow_over,
335  bool warn_over,
336  bool info_details,
337  const infinint & pause,
338  bool empty_dir,
339  compression algo,
340  U_I compression_level,
341  const infinint & file_size,
342  const infinint & first_file_size,
343  const mask & ea_mask,
344  const std::string & execute,
345  crypto_algo crypto,
346  const secu_string & pass,
347  U_32 crypto_size,
348  const mask & compr_mask,
349  const infinint & min_compr_size,
350  bool nodump,
351  const infinint & hourshift,
352  bool empty,
353  bool alter_atime,
354  bool furtive_read_mode,
355  bool same_fs,
356  inode::comparison_fields what_to_check,
357  bool snapshot,
358  bool cache_directory_tagging,
359  bool display_skipped,
360  const infinint & fixed_date,
361  const std::string & slice_permission,
362  const std::string & slice_user_ownership,
363  const std::string & slice_group_ownership,
364  const infinint & repeat_count,
365  const infinint & repeat_byte,
366  bool add_marks_for_sequential_reading,
367  bool security_check,
368  const infinint & sparse_file_min_size,
369  const std::string & user_comment,
370  hash_algo hash,
371  const infinint & slice_min_digits,
372  const std::string & backup_hook_file_execute,
373  const mask & backup_hook_file_mask,
374  bool ignore_unknown,
375  statistics * progressive_report);
376 
377  void op_create_in_sub(user_interaction & dialog, //< interaction with user
378  operation op, //< the filter operation to bind to
379  const path & fs_root, //< root of the filesystem to act on
380  const path & sauv_path_t, //< where to create the archive
381  catalogue * ref_arch1, //< catalogue of the archive of reference (a catalogue must be provided in any case, a empty one shall fit for no reference)
382  catalogue * ref_arch2, //< secondary catalogue used for merging, can be NULL if not used
383  const path * ref_path, //< path of the archive of archive of reference (NULL if there is no archive of reference used, thus ref_arch (previous arg) is probably an empty archive)
384  const mask & selection, //< filter on filenames
385  const mask & subtree, //< filter on directory tree and filenames
386  const std::string & filename, //< basename of the archive to create
387  const std::string & extension, //< extension of the archives
388  bool allow_over, //< whether to allow overwriting (of slices)
389  const crit_action & overwrite, //< whether and how to allow overwriting (for files inside the archive)
390  bool warn_over, //< whether to warn before overwriting
391  bool info_details, //< whether to display detailed informations
392  const infinint & pause, //< whether to pause between slices
393  bool empty_dir, //< whether to store excluded dir as empty directories
394  compression algo, //< compression algorithm
395  U_I compression_level, //< compression level (range 1 to 9)
396  const infinint & file_size, //< slice size
397  const infinint & first_file_size, //< first slice size
398  const mask & ea_mask, //< Extended Attribute to consider
399  const std::string & execute, //< Command line to execute between slices
400  crypto_algo crypto, //< crypt algorithm
401  const secu_string & pass, //< password ("" for onfly request of password)
402  U_32 crypto_size, //< size of crypto blocks
403  const mask & compr_mask, //< files to compress
404  const infinint & min_compr_size, //< file size under which to not compress files
405  bool nodump, //< whether to consider the "nodump" filesystem flag
406  const infinint & hourshift, //< hourshift (see man page -H option)
407  bool empty, //< whether to make an "dry-run" execution
408  bool alter_atime, //< whether to alter atime date (by opposition to ctime) when reading files
409  bool furtive_read_mode, //< whether to neither alter atime nor ctome (if true alter_atime is ignored)
410  bool same_fs, //< confin the files consideration to a single filesystem
411  inode::comparison_fields what_to_check, //< fields to consider wien comparing inodes (see inode::comparison_fields enumeration)
412  bool snapshot, //< make as if all file had not changed
413  bool cache_directory_tagging, //< avoid saving directory which follow the cache directory tagging
414  bool display_skipped, //< display skipped files for the operation
415  bool keep_compressed, //< keep file compressed when merging
416  const infinint & fixed_date, //< whether to ignore any archive of reference and only save file which modification is more recent that the given "fixed_date" date
417  const std::string & slice_permission, //< permissions of slices that will be created
418  const std::string & slice_user_ownership, //< user ownership of slices that will be created
419  const std::string & slice_group_ownership, //< group ownership of slices that will be created
420  const infinint & repeat_count, //< max number of retry to save a file that have changed while it was read for backup
421  const infinint & repeat_byte, //< max amount of wasted data used to save a file that have changed while it was read for backup
422  bool decremental, //< in the merging context only, whether to build a decremental backup from the two archives of reference
423  bool add_marks_for_sequential_reading, //< whether to add marks for sequential reading
424  bool security_check, //< whether to check for ctime change with no reason (rootkit ?)
425  const infinint & sparse_file_min_size, //< starting which size to consider looking for holes in sparse files (0 for no detection)
426  const std::string & user_comment, //< user comment to put in the archive
427  hash_algo hash, //< whether to produce hash file, and which algo to use
428  const infinint & slice_min_digits, //< minimum digit for slice number
429  const std::string & backup_hook_file_execute, //< command to execute before and after files to backup
430  const mask & backup_hook_file_mask, //< files elected to have a command executed before and after their backup
431  bool ignore_unknown, //< whether to warn when an unknown inode type is met
432  statistics * st_ptr); //< statistics must not be NULL !
433 
434  void disable_natural_destruction();
435  void enable_natural_destruction();
436  const label & get_layer1_data_name() const;
437  const label & get_catalogue_data_name() const;
438  bool only_contains_an_isolated_catalogue() const; //< true if the current archive only contains an isolated catalogue
439  void check_against_isolation(user_interaction & dialog, bool lax) const; //< throw Erange exception if the archive only contains an isolated catalogue
440  void check_header_version() const;
441  const directory *get_dir_object(const std::string & dir) const;
442  };
443 
444 } // end of namespace
445 
446 #endif
statistics op_extract(user_interaction &dialog, const path &fs_root, const archive_options_extract &options, statistics *progressive_report)
extraction of data from an archive
const catalogue & get_catalogue() const
gives access to internal catalogue (not to be used from the API)
the generic class, parent of all masks
Definition: mask.hpp:61
the catalogue class which gather all objects contained in a give archive
Definition: catalogue.hpp:979
holds the statistics contents of a catalogue
Definition: catalogue.hpp:70
statistics op_diff(user_interaction &dialog, const path &fs_root, const archive_options_diff &options, statistics *progressive_report)
archive comparison with filesystem
const char * dar_gettext(const char *)
a routine to change NLS domaine forth and back for inline routines
class holding optional parameters used to test the structure coherence of an existing archive ...
archive(const archive &ref)
copy constructor (not implemented, throw an exception if called explicitely or implicitely) ...
Definition: archive.hpp:148
class of objects describing an entry in the archive, used by archive::get_children_in_table ...
class pile definition. Used to manage a stack of generic_file objects
const entree_stats get_stats() const
retrieving statistics about archive contents
Definition: archive.hpp:270
This is a pure virtual class that is used by libdar when interaction with the user is required...
void init_catalogue(user_interaction &dialog) const
the directory inode class
Definition: catalogue.hpp:653
comparison_fields
flag used to only consider certain fields when comparing/restoring inodes
Definition: catalogue.hpp:209
the archive class realizes the most general operations on archives
Definition: archive.hpp:52
crypto_algo
the different cypher available for encryption (strong or weak)
Definition: crypto.hpp:53
const std::vector< list_entry > get_children_in_table(const std::string &dir) const
here is the definition of the path classthe path class handle path and provide several operation on t...
class escape_catalogue definition. Used for sequential writing to archives, as well as several other ...
exception used when a requested feature is not (yet) implemented
Definition: erreurs.hpp:200
handle the statistic structure that gives a summary of treated files after each operatio ...
class escape definition, used for sequential reading of archivesThe class escape is used to insert es...
archive(user_interaction &dialog, const path &chem, const std::string &basename, const std::string &extension, const archive_options_read &options)
this constructor opens an already existing archive (for reading) [this is the "read" constructor] ...
void summary(user_interaction &dialog)
the global action for overwriting
Definition: criterium.hpp:76
class holding optional parameters used to extract files from an existing archive
contains all the excetion class thrown by libdar
class secu_string
Definition: secu_string.hpp:57
compression
the different compression algorithm available
Definition: compressor.hpp:43
this file contains a set of classes used to transmit options to archive operation ...
bool nodump()
returns whether nodump flag support has been activated at compilation time
manages of the archive header and trailer
void drop_all_filedescriptors()
closes all filedescriptors and associated data, just keep the catalogue
~archive()
the destructor
Definition: archive.hpp:152
void op_listing(user_interaction &dialog, const archive_options_listing &options)
listing of the archive contents
contains the definition of the scrambler class, a very weak encryption scheme
class holding optional parameters used to list the contents of an existing archive ...
the arbitrary large positive integer class
class holding optional parameters used to read an existing archive
class holding optional parameters used to proceed to the merge operation
statistics op_test(user_interaction &dialog, const archive_options_test &options, statistics *progressive_report)
test the archive integrity
class holding optional parameters used to create an archive
class holding optional parameters used to isolate an existing archive
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43
bool get_children_of(user_interaction &dialog, const std::string &dir)
getting information about a given directory
structure returned by libdar call to give a summary of the operation done in term of file treated ...
Definition: statistics.hpp:68
the class path is here to manipulate paths in the Unix notation: using&#39;/&#39;
Definition: path.hpp:50