Disk ARchive  2.5.16
Full featured and portable backup and archiving tool
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 #include <string>
33 
34 #include "erreurs.hpp"
35 #include "path.hpp"
36 #include "scrambler.hpp"
37 #include "statistics.hpp"
38 #include "archive_options.hpp"
39 #include "escape.hpp"
40 #include "escape_catalogue.hpp"
41 #include "pile.hpp"
42 #include "list_entry.hpp"
43 #include "on_pool.hpp"
44 #include "crypto.hpp"
45 #include "slice_layout.hpp"
46 
47 namespace libdar
48 {
49 
51 
56  class archive : public on_pool
57  {
58  public:
59 
61 
68  archive(user_interaction & dialog,
69  const path & chem,
70  const std::string & basename,
71  const std::string & extension,
72  const archive_options_read & options);
73 
74 
76 
95  archive(user_interaction & dialog,
96  const path & fs_root,
97  const path & sauv_path,
98  const std::string & filename,
99  const std::string & extension,
100  const archive_options_create & options,
101  statistics * progressive_report);
102 
103 
106  archive(user_interaction & dialog,
107  const path & sauv_path,
108  archive *ref_arch,
109  const std::string & filename,
110  const std::string & extension,
111  const archive_options_isolate & options);
112 
113 
115 
130 
131  archive(user_interaction & dialog,
132  const path & sauv_path,
133  archive *ref_arch1,
134  const std::string & filename,
135  const std::string & extension,
136  const archive_options_merge & options,
137  statistics * progressive_report);
138 
140 
145 
146  archive(const archive & ref) : stack(ref.stack) { throw Efeature(dar_gettext("Archive copy constructor is not implemented")); };
147  archive & operator = (const archive & ref) { throw Efeature(dar_gettext("Archive assignment operator is not implemented")); };
148 
150  ~archive() throw(Ebug) { free_all(); };
151 
152 
154 
174  const path &fs_root,
175  const archive_options_extract & options,
176  statistics *progressive_report);
177 
181  void summary(user_interaction & dialog);
182 
183 
185 
194  void op_listing(user_interaction & dialog,
195  const archive_options_listing & options);
196 
198 
213  const path & fs_root,
214  const archive_options_diff & options,
215  statistics * progressive_report);
216 
217 
219 
240  const archive_options_test & options,
241  statistics * progressive_report);
242 
243 
245 
251  void op_isolate(user_interaction & dialog,
252  const path &sauv_path,
253  const std::string & filename,
254  const std::string & extension,
255  const archive_options_isolate & options);
256 
257 
259 
267  bool get_children_of(user_interaction & dialog,
268  const std::string & dir);
269 
279  const std::vector<list_entry> get_children_in_table(const std::string & dir) const;
280 
282  bool has_subdirectory(const std::string & dir) const;
283 
285  const entree_stats get_stats() const { if(cat == nullptr) throw SRC_BUG; return cat->get_stats(); };
286 
288  const std::list<signator> & get_signatories() const { return gnupg_signed; };
289 
292  void init_catalogue(user_interaction & dialog) const;
293 
295 
303  const catalogue & get_catalogue() const;
304 
306  const catalogue & get_catalogue(user_interaction & dialog) const;
307 
309 
316 
318 
320 
322  void set_to_unsaved_data_and_FSA() { if(cat == nullptr) throw SRC_BUG; cat->set_to_unsaved_data_and_FSA(); };
323 
330  std::string free_and_check_memory() const;
331 
341  U_64 get_first_slice_header_size() const;
342 
346  U_64 get_non_first_slice_header_size() const;
347 
348 
349  private:
350  enum operation { oper_create, oper_isolate, oper_merge };
351 
352  pile stack; //< the different layer through which the archive contents is read or wrote
353  header_version ver; //< information for the archive header
354  memory_pool *pool; //< points to local_pool or inherited pool or to nullptr if no memory_pool has to be used
355  catalogue *cat; //< archive contents
356  infinint local_cat_size; //< size of the catalogue on disk
357  bool exploitable; //< is false if only the catalogue is available (for reference backup or isolation).
358  bool lax_read_mode; //< whether the archive has been openned in lax mode (unused for creation/merging/isolation)
359  bool sequential_read; //< whether the archive is read in sequential mode
360  bool freed_and_checked; //< whether free_and_check has been run
361  std::list<signator> gnupg_signed; //< list of signature found in the archive (reading an existing archive)
362  slice_layout slices; //< slice layout, archive is not sliced <=> first_size or other_size fields is set to zero (in practice both are set to zero, but one being set is enought to determine the archive is not sliced)
363 
364  void free_except_memory_pool();
365  void free_all();
366  void init_pool();
367  void check_gnupg_signed(user_interaction & dialog) const;
368 
369  const catalogue & get_cat() const { if(cat == nullptr) throw SRC_BUG; else return *cat; };
370  const header_version & get_header() const { return ver; };
371 
372  bool get_sar_param(infinint & sub_file_size, infinint & first_file_size, infinint & last_file_size,
373  infinint & total_file_number);
374  const entrepot *get_entrepot(); //< this method may return nullptr if no entrepot is used (pipes used for archive building, etc.)
375  infinint get_level2_size();
376  infinint get_cat_size() const { return local_cat_size; };
377 
378  statistics op_create_in(user_interaction & dialog,
379  operation op,
380  const path & fs_root,
381  const entrepot & sauv_path_t,
382  archive *ref_arch,
383  const mask & selection,
384  const mask & subtree,
385  const std::string & filename,
386  const std::string & extension,
387  bool allow_over,
388  bool warn_over,
389  bool info_details,
390  bool display_treated,
391  bool display_treated_only_dir,
392  bool display_skipped,
393  bool display_finished,
394  const infinint & pause,
395  bool empty_dir,
396  compression algo,
397  U_I compression_level,
398  const infinint & file_size,
399  const infinint & first_file_size,
400  const mask & ea_mask,
401  const std::string & execute,
402  crypto_algo crypto,
403  const secu_string & pass,
404  U_32 crypto_size,
405  const std::vector<std::string> & gnupg_recipients,
406  const std::vector<std::string> & gnupg_signatories,
407  const mask & compr_mask,
408  const infinint & min_compr_size,
409  bool nodump,
410  const std::string & exclude_by_ea,
411  const infinint & hourshift,
412  bool empty,
413  bool alter_atime,
414  bool furtive_read_mode,
415  bool same_fs,
416  cat_inode::comparison_fields what_to_check,
417  bool snapshot,
418  bool cache_directory_tagging,
419  const infinint & fixed_date,
420  const std::string & slice_permission,
421  const infinint & repeat_count,
422  const infinint & repeat_byte,
423  bool add_marks_for_sequential_reading,
424  bool security_check,
425  const infinint & sparse_file_min_size,
426  const std::string & user_comment,
427  hash_algo hash,
428  const infinint & slice_min_digits,
429  const std::string & backup_hook_file_execute,
430  const mask & backup_hook_file_mask,
431  bool ignore_unknown,
432  const fsa_scope & scope,
433  bool multi_threaded,
434  bool zeroing_neg_date,
435  statistics * progressive_report);
436 
437  void op_create_in_sub(user_interaction & dialog, //< interaction with user
438  operation op, //< the filter operation to bind to
439  const path & fs_root, //< root of the filesystem to act on
440  const entrepot & sauv_path_t, //< where to create the archive
441  const catalogue * ref_cat1, //< catalogue of the archive of reference, (cannot be nullptr if ref_cat2 is not nullptr)
442  const catalogue * ref_cat2, //< secondary catalogue used for merging, can be nullptr if not used
443  bool initial_pause, //< whether we shall pause before starting the archive creation
444  const mask & selection, //< filter on filenames
445  const mask & subtree, //< filter on directory tree and filenames
446  const std::string & filename, //< basename of the archive to create
447  const std::string & extension, //< extension of the archives
448  bool allow_over, //< whether to allow overwriting (of slices)
449  const crit_action & overwrite, //< whether and how to allow overwriting (for files inside the archive)
450  bool warn_over, //< whether to warn before overwriting
451  bool info_details, //< whether to display detailed informations
452  bool display_treated, //< whether to display treated files
453  bool display_treated_only_dir, //< whether to only display current directory of treated files
454  bool display_skipped, //< display skipped files for the operation
455  bool display_finished, //< display space and compression ratio summary for each completed directory
456  const infinint & pause, //< whether to pause between slices
457  bool empty_dir, //< whether to store excluded dir as empty directories
458  compression algo, //< compression algorithm
459  U_I compression_level, //< compression level (range 1 to 9)
460  const infinint & file_size, //< slice size
461  const infinint & first_file_size, //< first slice size
462  const mask & ea_mask, //< Extended Attribute to consider
463  const std::string & execute, //< Command line to execute between slices
464  crypto_algo crypto, //< crypt algorithm
465  const secu_string & pass, //< password ("" for onfly request of password)
466  U_32 crypto_size, //< size of crypto blocks
467  const std::vector<std::string> & gnupg_recipients, //< list of email recipients to encrypted a randomly chosen key inside the archive
468  const std::vector<std::string> & gnupg_signatories, //< list of email recipients to use for signature
469  const mask & compr_mask, //< files to compress
470  const infinint & min_compr_size, //< file size under which to not compress files
471  bool nodump, //< whether to consider the "nodump" filesystem flag
472  const std::string & exclude_by_ea,//< if not empty the ea to use for inode exclusion from backup operation
473  const infinint & hourshift, //< hourshift (see man page -H option)
474  bool empty, //< whether to make an "dry-run" execution
475  bool alter_atime, //< whether to alter atime date (by opposition to ctime) when reading files
476  bool furtive_read_mode, //< whether to neither alter atime nor ctome (if true alter_atime is ignored)
477  bool same_fs, //< confin the files consideration to a single filesystem
478  cat_inode::comparison_fields what_to_check, //< fields to consider wien comparing inodes (see cat_inode::comparison_fields enumeration)
479  bool snapshot, //< make as if all file had not changed
480  bool cache_directory_tagging, //< avoid saving directory which follow the cache directory tagging
481  bool keep_compressed, //< keep file compressed when merging
482  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
483  const std::string & slice_permission, //< permissions of slices that will be created
484  const infinint & repeat_count, //< max number of retry to save a file that have changed while it was read for backup
485  const infinint & repeat_byte, //< max amount of wasted data used to save a file that have changed while it was read for backup
486  bool decremental, //< in the merging context only, whether to build a decremental backup from the two archives of reference
487  bool add_marks_for_sequential_reading, //< whether to add marks for sequential reading
488  bool security_check, //< whether to check for ctime change with no reason (rootkit ?)
489  const infinint & sparse_file_min_size, //< starting which size to consider looking for holes in sparse files (0 for no detection)
490  const std::string & user_comment, //< user comment to put in the archive
491  hash_algo hash, //< whether to produce hash file, and which algo to use
492  const infinint & slice_min_digits, //< minimum digit for slice number
493  const std::string & backup_hook_file_execute, //< command to execute before and after files to backup
494  const mask & backup_hook_file_mask, //< files elected to have a command executed before and after their backup
495  bool ignore_unknown, //< whether to warn when an unknown inode type is met
496  const fsa_scope & scope, //< FSA scope for the operation
497  bool multi_threaded, //< whether libdar is allowed to spawn several thread to possibily work faster on multicore CPU
498  bool zeroing_neg_date, //< if true just warn before zeroing neg date, dont ask user
499  statistics * st_ptr); //< statistics must not be nullptr !
500 
501  void disable_natural_destruction();
502  void enable_natural_destruction();
503  const label & get_layer1_data_name() const;
504  const label & get_catalogue_data_name() const;
505  bool only_contains_an_isolated_catalogue() const; //< true if the current archive only contains an isolated catalogue
506  void check_against_isolation(user_interaction & dialog, bool lax) const; //< throw Erange exception if the archive only contains an isolated catalogue
507  const cat_directory *get_dir_object(const std::string & dir) const;
508  };
509 
510 } // end of namespace
511 
512 #endif
const std::vector< list_entry > get_children_in_table(const std::string &dir) const
statistics op_extract(user_interaction &dialog, const path &fs_root, const archive_options_extract &options, statistics *progressive_report)
extraction of data from an archive
the generic class, parent of all masks
Definition: mask.hpp:62
U_64 get_first_slice_header_size() const
std::string free_and_check_memory() const
the catalogue class which gather all objects contained in a give archive
Definition: catalogue.hpp:62
holds the statistics contents of a catalogue
Definition: cat_entree.hpp:61
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 ...
const catalogue & get_catalogue() const
gives access to internal catalogue (not to be used from the API)
archive(const archive &ref)
copy constructor (not implemented, throw an exception if called explicitely or implicitely) ...
Definition: archive.hpp:146
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
bool has_subdirectory(const std::string &dir) const
returns true if the pointed directory has one or more subdirectories
This is a pure virtual class that is used by libdar when interaction with the user is required...
manages the archive header and trailer
the crypto algoritm definition
object describing the slicing of an archive
the cat_directory inode class
the archive class realizes the most general operations on archives
Definition: archive.hpp:56
crypto_algo
Definition: crypto.hpp:49
const std::list< signator > & get_signatories() const
retrieving signature information about the archive
Definition: archive.hpp:288
here is the definition of the path classthe path class handle path and provide several operation on t...
U_64 get_non_first_slice_header_size() const
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:206
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)
void op_isolate(user_interaction &dialog, const path &sauv_path, const std::string &filename, const std::string &extension, const archive_options_isolate &options)
this methodes isolates the catalogue of a the current archive into a separated archive ...
the global action for overwriting
Definition: criterium.hpp:77
class holding optional parameters used to extract files from an existing archive
contains all the excetion class thrown by libdar
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
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
void drop_all_filedescriptors()
closes all filedescriptors and associated data, just keep the catalogue
~archive()
the destructor
Definition: archive.hpp:150
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
this is the base class of object that can be allocated on a memory pool
class holding optional parameters used to list the contents of an existing archive ...
const entree_stats get_stats() const
retrieving statistics about archive contents
Definition: archive.hpp:285
the arbitrary large positive integer class
void set_to_unsaved_data_and_FSA()
change all inode as unsaved (equal to differential backup with no change met)
Definition: archive.hpp:322
void init_catalogue(user_interaction &dialog) const
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
the Entrepot interface
Definition: entrepot.hpp:61
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
comparison_fields
flag used to only consider certain fields when comparing/restoring inodes
Definition: cat_inode.hpp:60
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