Disk ARchive  2.5.3
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 
332 
333  private:
334  enum operation { oper_create, oper_isolate, oper_merge };
335 
336  pile stack; //< the different layer through which the archive contents is read or wrote
337  header_version ver; //< information for the archive header
338  memory_pool *pool; //< points to local_pool or inherited pool or to nullptr if no memory_pool has to be used
339  catalogue *cat; //< archive contents
340  infinint local_cat_size; //< size of the catalogue on disk
341  bool exploitable; //< is false if only the catalogue is available (for reference backup or isolation).
342  bool lax_read_mode; //< whether the archive has been openned in lax mode (unused for creation/merging/isolation)
343  bool sequential_read; //< whether the archive is read in sequential mode
344  bool freed_and_checked; //< whether free_and_check has been run
345  std::list<signator> gnupg_signed; //< list of signature found in the archive (reading an existing archive)
346  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)
347 
348  void free_except_memory_pool();
349  void free_all();
350  void init_pool();
351  void check_gnupg_signed(user_interaction & dialog) const;
352 
353  const catalogue & get_cat() const { if(cat == nullptr) throw SRC_BUG; else return *cat; };
354  const header_version & get_header() const { return ver; };
355 
356  bool get_sar_param(infinint & sub_file_size, infinint & first_file_size, infinint & last_file_size,
357  infinint & total_file_number);
358  const entrepot *get_entrepot(); //< this method may return nullptr if no entrepot is used (pipes used for archive building, etc.)
359  infinint get_level2_size();
360  infinint get_cat_size() const { return local_cat_size; };
361 
362  statistics op_create_in(user_interaction & dialog,
363  operation op,
364  const path & fs_root,
365  const entrepot & sauv_path_t,
366  archive *ref_arch,
367  const mask & selection,
368  const mask & subtree,
369  const std::string & filename,
370  const std::string & extension,
371  bool allow_over,
372  bool warn_over,
373  bool info_details,
374  bool display_treated,
375  bool display_treated_only_dir,
376  bool display_skipped,
377  bool display_finished,
378  const infinint & pause,
379  bool empty_dir,
380  compression algo,
381  U_I compression_level,
382  const infinint & file_size,
383  const infinint & first_file_size,
384  const mask & ea_mask,
385  const std::string & execute,
386  crypto_algo crypto,
387  const secu_string & pass,
388  U_32 crypto_size,
389  const std::vector<std::string> & gnupg_recipients,
390  const std::vector<std::string> & gnupg_signatories,
391  const mask & compr_mask,
392  const infinint & min_compr_size,
393  bool nodump,
394  const std::string & exclude_by_ea,
395  const infinint & hourshift,
396  bool empty,
397  bool alter_atime,
398  bool furtive_read_mode,
399  bool same_fs,
400  cat_inode::comparison_fields what_to_check,
401  bool snapshot,
402  bool cache_directory_tagging,
403  const infinint & fixed_date,
404  const std::string & slice_permission,
405  const infinint & repeat_count,
406  const infinint & repeat_byte,
407  bool add_marks_for_sequential_reading,
408  bool security_check,
409  const infinint & sparse_file_min_size,
410  const std::string & user_comment,
411  hash_algo hash,
412  const infinint & slice_min_digits,
413  const std::string & backup_hook_file_execute,
414  const mask & backup_hook_file_mask,
415  bool ignore_unknown,
416  const fsa_scope & scope,
417  bool multi_threaded,
418  statistics * progressive_report);
419 
420  void op_create_in_sub(user_interaction & dialog, //< interaction with user
421  operation op, //< the filter operation to bind to
422  const path & fs_root, //< root of the filesystem to act on
423  const entrepot & sauv_path_t, //< where to create the archive
424  const catalogue * ref_cat1, //< catalogue of the archive of reference, (cannot be nullptr if ref_cat2 is not nullptr)
425  const catalogue * ref_cat2, //< secondary catalogue used for merging, can be nullptr if not used
426  bool initial_pause, //< whether we shall pause before starting the archive creation
427  const mask & selection, //< filter on filenames
428  const mask & subtree, //< filter on directory tree and filenames
429  const std::string & filename, //< basename of the archive to create
430  const std::string & extension, //< extension of the archives
431  bool allow_over, //< whether to allow overwriting (of slices)
432  const crit_action & overwrite, //< whether and how to allow overwriting (for files inside the archive)
433  bool warn_over, //< whether to warn before overwriting
434  bool info_details, //< whether to display detailed informations
435  bool display_treated, //< whether to display treated files
436  bool display_treated_only_dir, //< whether to only display current directory of treated files
437  bool display_skipped, //< display skipped files for the operation
438  bool display_finished, //< display space and compression ratio summary for each completed directory
439  const infinint & pause, //< whether to pause between slices
440  bool empty_dir, //< whether to store excluded dir as empty directories
441  compression algo, //< compression algorithm
442  U_I compression_level, //< compression level (range 1 to 9)
443  const infinint & file_size, //< slice size
444  const infinint & first_file_size, //< first slice size
445  const mask & ea_mask, //< Extended Attribute to consider
446  const std::string & execute, //< Command line to execute between slices
447  crypto_algo crypto, //< crypt algorithm
448  const secu_string & pass, //< password ("" for onfly request of password)
449  U_32 crypto_size, //< size of crypto blocks
450  const std::vector<std::string> & gnupg_recipients, //< list of email recipients to encrypted a randomly chosen key inside the archive
451  const std::vector<std::string> & gnupg_signatories, //< list of email recipients to use for signature
452  const mask & compr_mask, //< files to compress
453  const infinint & min_compr_size, //< file size under which to not compress files
454  bool nodump, //< whether to consider the "nodump" filesystem flag
455  const std::string & exclude_by_ea,//< if not empty the ea to use for inode exclusion from backup operation
456  const infinint & hourshift, //< hourshift (see man page -H option)
457  bool empty, //< whether to make an "dry-run" execution
458  bool alter_atime, //< whether to alter atime date (by opposition to ctime) when reading files
459  bool furtive_read_mode, //< whether to neither alter atime nor ctome (if true alter_atime is ignored)
460  bool same_fs, //< confin the files consideration to a single filesystem
461  cat_inode::comparison_fields what_to_check, //< fields to consider wien comparing inodes (see cat_inode::comparison_fields enumeration)
462  bool snapshot, //< make as if all file had not changed
463  bool cache_directory_tagging, //< avoid saving directory which follow the cache directory tagging
464  bool keep_compressed, //< keep file compressed when merging
465  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
466  const std::string & slice_permission, //< permissions of slices that will be created
467  const infinint & repeat_count, //< max number of retry to save a file that have changed while it was read for backup
468  const infinint & repeat_byte, //< max amount of wasted data used to save a file that have changed while it was read for backup
469  bool decremental, //< in the merging context only, whether to build a decremental backup from the two archives of reference
470  bool add_marks_for_sequential_reading, //< whether to add marks for sequential reading
471  bool security_check, //< whether to check for ctime change with no reason (rootkit ?)
472  const infinint & sparse_file_min_size, //< starting which size to consider looking for holes in sparse files (0 for no detection)
473  const std::string & user_comment, //< user comment to put in the archive
474  hash_algo hash, //< whether to produce hash file, and which algo to use
475  const infinint & slice_min_digits, //< minimum digit for slice number
476  const std::string & backup_hook_file_execute, //< command to execute before and after files to backup
477  const mask & backup_hook_file_mask, //< files elected to have a command executed before and after their backup
478  bool ignore_unknown, //< whether to warn when an unknown inode type is met
479  const fsa_scope & scope, //< FSA scope for the operation
480  bool multi_threaded, //< whether libdar is allowed to spawn several thread to possibily work faster on multicore CPU
481  statistics * st_ptr); //< statistics must not be nullptr !
482 
483  void disable_natural_destruction();
484  void enable_natural_destruction();
485  const label & get_layer1_data_name() const;
486  const label & get_catalogue_data_name() const;
487  bool only_contains_an_isolated_catalogue() const; //< true if the current archive only contains an isolated catalogue
488  void check_against_isolation(user_interaction & dialog, bool lax) const; //< throw Erange exception if the archive only contains an isolated catalogue
489  const cat_directory *get_dir_object(const std::string & dir) const;
490  };
491 
492 } // end of namespace
493 
494 #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 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:60
bool has_subdirectory(const std::string &dir) const
returns true if the pointed directory has one or more subdirectories
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: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
const entree_stats get_stats() const
retrieving statistics about archive contents
Definition: archive.hpp:285
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 crypto algoritm definition
object describing the slicing of an archive
the archive class realizes the most general operations on archives
Definition: archive.hpp:56
crypto_algo
the different cypher available for encryption (strong or weak)
Definition: crypto.hpp:51
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: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 ...
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
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 ...
std::string free_and_check_memory() const
comparison_fields
flag used to only consider certain fields when comparing/restoring inodes
Definition: cat_inode.hpp:60
void set_to_unsaved_data_and_FSA()
change all inode as unsaved (equal to differential backup with no change met)
Definition: archive.hpp:322
const std::list< signator > & get_signatories() const
retrieving signature information about the archive
Definition: archive.hpp:288
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:47
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'/'
Definition: path.hpp:50