Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
archive.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 
00027 #ifndef ARCHIVE_HPP
00028 #define ARCHIVE_HPP
00029 
00030 #include "../my_config.h"
00031 #include <vector>
00032 #include <string>
00033 
00034 #include "erreurs.hpp"
00035 #include "path.hpp"
00036 #include "scrambler.hpp"
00037 #include "statistics.hpp"
00038 #include "archive_options.hpp"
00039 #include "escape.hpp"
00040 #include "escape_catalogue.hpp"
00041 #include "pile.hpp"
00042 #include "list_entry.hpp"
00043 #include "on_pool.hpp"
00044 #include "crypto.hpp"
00045 #include "slice_layout.hpp"
00046 
00047 namespace libdar
00048 {
00049 
00051 
00056     class archive : public on_pool
00057     {
00058     public:
00059 
00061 
00068     archive(user_interaction & dialog,
00069         const path & chem,
00070         const std::string & basename,
00071         const std::string & extension,
00072         const archive_options_read & options);
00073 
00074 
00076 
00095     archive(user_interaction & dialog,
00096         const path & fs_root,
00097         const path & sauv_path,
00098         const std::string & filename,
00099         const std::string & extension,
00100         const archive_options_create & options,
00101         statistics * progressive_report);
00102 
00103 
00106     archive(user_interaction & dialog,
00107         const path & sauv_path,
00108         archive *ref_arch,
00109         const std::string & filename,
00110         const std::string & extension,
00111         const archive_options_isolate & options);
00112 
00113 
00115 
00130 
00131     archive(user_interaction & dialog,
00132         const path & sauv_path,
00133         archive *ref_arch1,
00134         const std::string & filename,
00135         const std::string & extension,
00136         const archive_options_merge & options,
00137         statistics * progressive_report);
00138 
00140 
00145 
00146     archive(const archive & ref) : stack(ref.stack) { throw Efeature(dar_gettext("Archive copy constructor is not implemented")); };
00147     archive & operator = (const archive & ref) { throw Efeature(dar_gettext("Archive assignment operator is not implemented")); };
00148 
00150     ~archive() throw(Ebug) { free_all(); };
00151 
00152 
00154 
00173     statistics op_extract(user_interaction & dialog,
00174                   const path &fs_root,
00175                   const archive_options_extract & options,
00176                   statistics *progressive_report);
00177 
00181     void summary(user_interaction & dialog);
00182 
00183 
00185 
00194     void op_listing(user_interaction & dialog,
00195             const archive_options_listing & options);
00196 
00198 
00212     statistics op_diff(user_interaction & dialog,
00213                const path & fs_root,
00214                const archive_options_diff & options,
00215                statistics * progressive_report);
00216 
00217 
00219 
00239     statistics op_test(user_interaction & dialog,
00240                const archive_options_test & options,
00241                statistics * progressive_report);
00242 
00243 
00245 
00251     void op_isolate(user_interaction & dialog,
00252             const path &sauv_path,
00253             const std::string & filename,
00254             const std::string & extension,
00255             const archive_options_isolate & options);
00256 
00257 
00259 
00267     bool get_children_of(user_interaction & dialog,
00268                  const std::string & dir);
00269 
00279     const std::vector<list_entry> get_children_in_table(const std::string & dir) const;
00280 
00282     bool has_subdirectory(const std::string & dir) const;
00283 
00285     const entree_stats get_stats() const { if(cat == nullptr) throw SRC_BUG; return cat->get_stats(); };
00286 
00288     const std::list<signator> & get_signatories() const { return gnupg_signed; };
00289 
00292     void init_catalogue(user_interaction & dialog) const;
00293 
00295 
00303     const catalogue & get_catalogue() const;
00304 
00306     const catalogue & get_catalogue(user_interaction & dialog) const;
00307 
00309 
00315     void drop_all_filedescriptors();
00316 
00318 
00319     void drop_all_filedescriptors(user_interaction & dialog);
00320 
00322     void set_to_unsaved_data_and_FSA() { if(cat == nullptr) throw SRC_BUG; cat->set_to_unsaved_data_and_FSA(); };
00323 
00330     std::string free_and_check_memory() const;
00331 
00332 
00333     private:
00334     enum operation { oper_create, oper_isolate, oper_merge };
00335 
00336     pile stack;              //< the different layer through which the archive contents is read or wrote
00337     header_version ver;      //< information for the archive header
00338     memory_pool *pool;       //< points to local_pool or inherited pool or to nullptr if no memory_pool has to be used
00339     catalogue *cat;          //< archive contents
00340     infinint local_cat_size; //< size of the catalogue on disk
00341     bool exploitable;        //< is false if only the catalogue is available (for reference backup or isolation).
00342     bool lax_read_mode;      //< whether the archive has been openned in lax mode (unused for creation/merging/isolation)
00343     bool sequential_read;    //< whether the archive is read in sequential mode
00344     bool freed_and_checked;  //< whether free_and_check has been run
00345     std::list<signator> gnupg_signed; //< list of signature found in the archive (reading an existing archive)
00346     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)
00347 
00348     void free_except_memory_pool();
00349     void free_all();
00350     void init_pool();
00351     void check_gnupg_signed(user_interaction & dialog) const;
00352 
00353     const catalogue & get_cat() const { if(cat == nullptr) throw SRC_BUG; else return *cat; };
00354     const header_version & get_header() const { return ver; };
00355 
00356     bool get_sar_param(infinint & sub_file_size, infinint & first_file_size, infinint & last_file_size,
00357                infinint & total_file_number);
00358     const entrepot *get_entrepot(); //< this method may return nullptr if no entrepot is used (pipes used for archive building, etc.)
00359     infinint get_level2_size();
00360     infinint get_cat_size() const { return local_cat_size; };
00361 
00362     statistics op_create_in(user_interaction & dialog,
00363                 operation op,
00364                 const path & fs_root,
00365                 const entrepot & sauv_path_t,
00366                 archive *ref_arch,
00367                 const mask & selection,
00368                 const mask & subtree,
00369                 const std::string & filename,
00370                 const std::string & extension,
00371                 bool allow_over,
00372                 bool warn_over,
00373                 bool info_details,
00374                 bool display_treated,
00375                 bool display_treated_only_dir,
00376                 bool display_skipped,
00377                 bool display_finished,
00378                 const infinint & pause,
00379                 bool empty_dir,
00380                 compression algo,
00381                 U_I compression_level,
00382                 const infinint & file_size,
00383                 const infinint & first_file_size,
00384                 const mask & ea_mask,
00385                 const std::string & execute,
00386                 crypto_algo crypto,
00387                 const secu_string & pass,
00388                 U_32 crypto_size,
00389                 const std::vector<std::string> & gnupg_recipients,
00390                 const std::vector<std::string> & gnupg_signatories,
00391                 const mask & compr_mask,
00392                 const infinint & min_compr_size,
00393                 bool nodump,
00394                 const std::string & exclude_by_ea,
00395                 const infinint & hourshift,
00396                 bool empty,
00397                 bool alter_atime,
00398                 bool furtive_read_mode,
00399                 bool same_fs,
00400                 cat_inode::comparison_fields what_to_check,
00401                 bool snapshot,
00402                 bool cache_directory_tagging,
00403                 const infinint & fixed_date,
00404                 const std::string & slice_permission,
00405                 const infinint & repeat_count,
00406                 const infinint & repeat_byte,
00407                 bool add_marks_for_sequential_reading,
00408                 bool security_check,
00409                 const infinint & sparse_file_min_size,
00410                 const std::string & user_comment,
00411                 hash_algo hash,
00412                 const infinint & slice_min_digits,
00413                 const std::string & backup_hook_file_execute,
00414                 const mask & backup_hook_file_mask,
00415                 bool ignore_unknown,
00416                 const fsa_scope & scope,
00417                 bool multi_threaded,
00418                 statistics * progressive_report);
00419 
00420     void op_create_in_sub(user_interaction & dialog,        //< interaction with user
00421                   operation op,                     //< the filter operation to bind to
00422                   const path & fs_root,             //< root of the filesystem to act on
00423                   const entrepot & sauv_path_t,     //< where to create the archive
00424                   const catalogue * ref_cat1,       //< catalogue of the archive of reference, (cannot be nullptr if ref_cat2 is not nullptr)
00425                   const catalogue * ref_cat2,       //< secondary catalogue used for merging, can be nullptr if not used
00426                   bool initial_pause,               //< whether we shall pause before starting the archive creation
00427                   const mask & selection,           //< filter on filenames
00428                   const mask & subtree,             //< filter on directory tree and filenames
00429                   const std::string & filename,     //< basename of the archive to create
00430                   const std::string & extension,    //< extension of the archives
00431                   bool allow_over,                  //< whether to allow overwriting (of slices)
00432                   const crit_action & overwrite,    //< whether and how to allow overwriting (for files inside the archive)
00433                   bool warn_over,                   //< whether to warn before overwriting
00434                   bool info_details,                //< whether to display detailed informations
00435                   bool display_treated,             //< whether to display treated files
00436                   bool display_treated_only_dir,    //< whether to only display current directory of treated files
00437                   bool display_skipped,             //< display skipped files for the operation
00438                   bool display_finished,            //< display space and compression ratio summary for each completed directory
00439                   const infinint & pause,           //< whether to pause between slices
00440                   bool empty_dir,                   //< whether to store excluded dir as empty directories
00441                   compression algo,                 //< compression algorithm
00442                   U_I compression_level,            //< compression level (range 1 to 9)
00443                   const infinint & file_size,       //< slice size
00444                   const infinint & first_file_size, //< first slice size
00445                   const mask & ea_mask,             //< Extended Attribute to consider
00446                   const std::string & execute,      //< Command line to execute between slices
00447                   crypto_algo crypto,               //< crypt algorithm
00448                   const secu_string & pass,         //< password ("" for onfly request of password)
00449                   U_32 crypto_size,                 //< size of crypto blocks
00450                   const std::vector<std::string> & gnupg_recipients, //< list of email recipients to encrypted a randomly chosen key inside the archive
00451                   const std::vector<std::string> & gnupg_signatories, //< list of email recipients to use for signature
00452                   const mask & compr_mask,          //< files to compress
00453                   const infinint & min_compr_size,  //< file size under which to not compress files
00454                   bool nodump,                      //< whether to consider the "nodump" filesystem flag
00455                   const std::string & exclude_by_ea,//< if not empty the ea to use for inode exclusion from backup operation
00456                   const infinint & hourshift,       //< hourshift (see man page -H option)
00457                   bool empty,                       //< whether to make an "dry-run" execution
00458                   bool alter_atime,                 //< whether to alter atime date (by opposition to ctime) when reading files
00459                   bool furtive_read_mode,           //< whether to neither alter atime nor ctome (if true alter_atime is ignored)
00460                   bool same_fs,                     //< confin the files consideration to a single filesystem
00461                   cat_inode::comparison_fields what_to_check,  //< fields to consider wien comparing inodes (see cat_inode::comparison_fields enumeration)
00462                   bool snapshot,                    //< make as if all file had not changed
00463                   bool cache_directory_tagging,     //< avoid saving directory which follow the cache directory tagging
00464                   bool keep_compressed,             //< keep file compressed when merging
00465                   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
00466                   const std::string & slice_permission,      //< permissions of slices that will be created
00467                   const infinint & repeat_count,             //< max number of retry to save a file that have changed while it was read for backup
00468                   const infinint & repeat_byte,              //< max amount of wasted data used to save a file that have changed while it was read for backup
00469                   bool decremental,                          //< in the merging context only, whether to build a decremental backup from the two archives of reference
00470                   bool add_marks_for_sequential_reading,     //< whether to add marks for sequential reading
00471                   bool security_check,                       //< whether to check for ctime change with no reason (rootkit ?)
00472                   const infinint & sparse_file_min_size,     //< starting which size to consider looking for holes in sparse files (0 for no detection)
00473                   const std::string & user_comment,          //< user comment to put in the archive
00474                   hash_algo hash,                            //< whether to produce hash file, and which algo to use
00475                   const infinint & slice_min_digits,         //< minimum digit for slice number
00476                   const std::string & backup_hook_file_execute, //< command to execute before and after files to backup
00477                   const mask & backup_hook_file_mask,         //< files elected to have a command executed before and after their backup
00478                   bool ignore_unknown,                        //< whether to warn when an unknown inode type is met
00479                   const fsa_scope & scope,                    //< FSA scope for the operation
00480                   bool multi_threaded,              //< whether libdar is allowed to spawn several thread to possibily work faster on multicore CPU
00481                   statistics * st_ptr);             //< statistics must not be nullptr !
00482 
00483     void disable_natural_destruction();
00484     void enable_natural_destruction();
00485     const label & get_layer1_data_name() const;
00486     const label & get_catalogue_data_name() const;
00487     bool only_contains_an_isolated_catalogue() const; //< true if the current archive only contains an isolated catalogue
00488     void check_against_isolation(user_interaction & dialog, bool lax) const; //< throw Erange exception if the archive only contains an isolated catalogue
00489     const cat_directory *get_dir_object(const std::string & dir) const;
00490     };
00491 
00492 } // end of namespace
00493 
00494 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines