Disk ARchive  2.4.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 
32 #include "path.hpp"
33 #include "scrambler.hpp"
34 #include "statistics.hpp"
35 #include "archive_options.hpp"
36 #include "escape.hpp"
37 #include "escape_catalogue.hpp"
38 #include "pile.hpp"
39 
40 namespace libdar
41 {
42 
44 
49  class archive
50  {
51  public:
52 
54 
61  archive(user_interaction & dialog,
62  const path & chem,
63  const std::string & basename,
64  const std::string & extension,
65  const archive_options_read & options);
66 
67 
69 
88  archive(user_interaction & dialog,
89  const path & fs_root,
90  const path & sauv_path,
91  const std::string & filename,
92  const std::string & extension,
93  const archive_options_create & options,
94  statistics * progressive_report);
95 
96 
98 
105  archive(user_interaction & dialog,
106  const path &sauv_path,
107  archive *ref_arch,
108  const std::string & filename,
109  const std::string & extension,
110  const archive_options_isolate & options);
111 
112 
114 
129 
130  archive(user_interaction & dialog,
131  const path & sauv_path,
132  archive *ref_arch1,
133  const std::string & filename,
134  const std::string & extension,
135  const archive_options_merge & options,
136  statistics * progressive_report);
137 
139 
144 
145  archive(const archive & ref) : stack(ref.stack) { throw Efeature(gettext("Archive copy constructor is not implemented")); };
146  archive & operator = (const archive & ref) { throw Efeature(gettext("Archive assignment operator is not implemented")); };
147 
149  ~archive() { free(); };
150 
151 
153 
173  const path &fs_root,
174  const archive_options_extract & options,
175  statistics *progressive_report);
176 
178 
179  void summary(user_interaction & dialog);
180 
181 
183 
186  void op_listing(user_interaction & dialog,
187  const archive_options_listing & options);
188 
190 
205  const path & fs_root,
206  const archive_options_diff & options,
207  statistics * progressive_report);
208 
209 
211 
232  const archive_options_test & options,
233  statistics * progressive_report);
234 
235 
237 
245  bool get_children_of(user_interaction & dialog,
246  const std::string & dir);
247 
249  const entree_stats get_stats() const { if(cat == NULL) throw SRC_BUG; return cat->get_stats(); };
250 
252 
259  const catalogue & get_catalogue() const;
260 
262  const catalogue & get_catalogue(user_interaction & dialog) const;
263 
265 
272 
274 
276 
277  private:
278  enum operation { oper_create, oper_isolate, oper_merge };
279 
280  pile stack;
281  header_version ver;
282  catalogue *cat;
283  infinint local_cat_size;
284  path *local_path;
285  bool exploitable; //< is false if only the catalogue is available (for reference backup or isolation).
286  bool lax_read_mode; //< whether the archive has been openned in lax mode (unused for creation/merging/isolation)
287  bool sequential_read; //< whether the archive is read in sequential mode
288 
289  void free();
290  catalogue & get_cat() { if(cat == NULL) throw SRC_BUG; else return *cat; };
291  const header_version & get_header() const { return ver; };
292  const path & get_path() { if(local_path == NULL) throw SRC_BUG; else return *local_path; };
293 
294  bool get_sar_param(infinint & sub_file_size, infinint & first_file_size, infinint & last_file_size,
295  infinint & total_file_number);
296  infinint get_level2_size();
297  infinint get_cat_size() const { return local_cat_size; };
298 
299  statistics op_create_in(user_interaction & dialog,
300  operation op,
301  const path & fs_root,
302  const path & sauv_path,
303  archive *ref_arch,
304  const mask & selection,
305  const mask & subtree,
306  const std::string & filename,
307  const std::string & extension,
308  bool allow_over,
309  bool warn_over,
310  bool info_details,
311  const infinint & pause,
312  bool empty_dir,
313  compression algo,
314  U_I compression_level,
315  const infinint & file_size,
316  const infinint & first_file_size,
317  const mask & ea_mask,
318  const std::string & execute,
319  crypto_algo crypto,
320  const secu_string & pass,
321  U_32 crypto_size,
322  const mask & compr_mask,
323  const infinint & min_compr_size,
324  bool nodump,
325  const infinint & hourshift,
326  bool empty,
327  bool alter_atime,
328  bool furtive_read_mode,
329  bool same_fs,
330  inode::comparison_fields what_to_check,
331  bool snapshot,
332  bool cache_directory_tagging,
333  bool display_skipped,
334  const infinint & fixed_date,
335  const std::string & slice_permission,
336  const std::string & slice_user_ownership,
337  const std::string & slice_group_ownership,
338  const infinint & repeat_count,
339  const infinint & repeat_byte,
340  bool add_marks_for_sequential_reading,
341  bool security_check,
342  const infinint & sparse_file_min_size,
343  const std::string & user_comment,
344  hash_algo hash,
345  const infinint & slice_min_digits,
346  const std::string & backup_hook_file_execute,
347  const mask & backup_hook_file_mask,
348  bool ignore_unknown,
349  statistics * progressive_report);
350 
351  void op_create_in_sub(user_interaction & dialog, //< interaction with user
352  operation op, //< the filter operation to bind to
353  const path & fs_root, //< root of the filesystem to act on
354  const path & sauv_path_t, //< where to create the archive
355  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)
356  catalogue * ref_arch2, //< secondary catalogue used for merging, can be NULL if not used
357  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)
358  const mask & selection, //< filter on filenames
359  const mask & subtree, //< filter on directory tree and filenames
360  const std::string & filename, //< basename of the archive to create
361  const std::string & extension, //< extension of the archives
362  bool allow_over, //< whether to allow overwriting (of slices)
363  const crit_action & overwrite, //< whether and how to allow overwriting (for files inside the archive)
364  bool warn_over, //< whether to warn before overwriting
365  bool info_details, //< whether to display detailed informations
366  const infinint & pause, //< whether to pause between slices
367  bool empty_dir, //< whether to store excluded dir as empty directories
368  compression algo, //< compression algorithm
369  U_I compression_level, //< compression level (range 1 to 9)
370  const infinint & file_size, //< slice size
371  const infinint & first_file_size, //< first slice size
372  const mask & ea_mask, //< Extended Attribute to consider
373  const std::string & execute, //< Command line to execute between slices
374  crypto_algo crypto, //< crypt algorithm
375  const secu_string & pass, //< password ("" for onfly request of password)
376  U_32 crypto_size, //< size of crypto blocks
377  const mask & compr_mask, //< files to compress
378  const infinint & min_compr_size, //< file size under which to not compress files
379  bool nodump, //< whether to consider the "nodump" filesystem flag
380  const infinint & hourshift, //< hourshift (see man page -H option)
381  bool empty, //< whether to make an "dry-run" execution
382  bool alter_atime, //< whether to alter atime date (by opposition to ctime) when reading files
383  bool furtive_read_mode, //< whether to neither alter atime nor ctome (if true alter_atime is ignored)
384  bool same_fs, //< confin the files consideration to a single filesystem
385  inode::comparison_fields what_to_check, //< fields to consider wien comparing inodes (see inode::comparison_fields enumeration)
386  bool snapshot, //< make as if all file had not changed
387  bool cache_directory_tagging, //< avoid saving directory which follow the cache directory tagging
388  bool display_skipped, //< display skipped files for the operation
389  bool keep_compressed, //< keep file compressed when merging
390  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
391  const std::string & slice_permission, //< permissions of slices that will be created
392  const std::string & slice_user_ownership, //< user ownership of slices that will be created
393  const std::string & slice_group_ownership, //< group ownership of slices that will be created
394  const infinint & repeat_count, //< max number of retry to save a file that have changed while it was read for backup
395  const infinint & repeat_byte, //< max amount of wasted data used to save a file that have changed while it was read for backup
396  bool decremental, //< in the merging context only, whether to build a decremental backup from the two archives of reference
397  bool add_marks_for_sequential_reading, //< whether to add marks for sequential reading
398  bool security_check, //< whether to check for ctime change with no reason (rootkit ?)
399  const infinint & sparse_file_min_size, //< starting which size to consider looking for holes in sparse files (0 for no detection)
400  const std::string & user_comment, //< user comment to put in the archive
401  hash_algo hash, //< whether to produce hash file, and which algo to use
402  const infinint & slice_min_digits, //< minimum digit for slice number
403  const std::string & backup_hook_file_execute, //< command to execute before and after files to backup
404  const mask & backup_hook_file_mask, //< files elected to have a command executed before and after their backup
405  bool ignore_unknown, //< whether to warn when an unknown inode type is met
406  statistics * st_ptr); //< statistics must not be NULL !
407 
408  void disable_natural_destruction();
409  void enable_natural_destruction();
410  const label & get_layer1_data_name() const;
411  const label & get_catalogue_data_name() const;
412  bool only_contains_an_isolated_catalogue() const; //< true if the current archive only contains an isolated catalogue
413  void check_against_isolation(user_interaction & dialog, bool lax) const; //< throw Erange exception if the archive only contains an isolated catalogue
414  void check_header_version() const;
415  };
416 
417 } // end of namespace
418 
419 #endif