1 #ifndef __archiver_h__ 2 #define __archiver_h__ 3 4 #include <string> 5 #include <map> 6 7 #include "asserts.h" 8 #include "estring.h" 9 #include "timer.h" 10 #include "exec.h" 11 #include "rconfig.h" 12 #include "logger.h" 13 #include "vaulter.h" 14 #include "reporter.h" 15 16 /** Map exit codes and signal numbers to verbose strings */ 17 class rstat 18 { 19 public: 20 rstat(); 21 const std::string& exit(const int a_int) const; 22 const std::string& signal(const int a_int) const; 23 24 private: 25 std::map<int,std::string> m_exit_str; 26 std::map<int,std::string> m_signal_str; 27 std::string m_unknown_exit; 28 std::string m_unknown_signal; 29 }; 30 31 extern class rstat rsync_estat_str; 32 33 class archiver; 34 35 /** Archive the paths associated with a single job */ 36 class job_archiver { 37 public: 38 enum archiving_status { 39 status_pending, 40 status_processing, 41 status_reschedule, 42 status_fatal_error, 43 status_error, 44 status_completed, 45 status_done, 46 }; 47 48 job_archiver(const job * a_job); 49 const std::string prefix(void); 50 const std::string id(void); 51 void clear(void); 52 void end(void); 53 const archiving_status status(void); 54 void start(void); 55 void process(void); 56 57 single_job_report report(void) const; 58 59 private: 60 const job* m_job; 61 archiving_status m_status; 62 timer m_timer; 63 timer m_io_timer; 64 bool m_rsync_timeout_flag; 65 execute m_exec; 66 bool m_success; 67 estring m_io_out; 68 estring m_io_err; 69 pid_t m_child_pid; 70 job_path_report m_jpr; 71 single_job_report m_jr; 72 std::string m_error_msg; 73 74 void mf_do_chores(void); 75 void mf_process_report(const std::string& a_str); 76 void mf_process_child_io(bool a_finalize); 77 void mf_process_rsync_io( 78 execute& a_exec, 79 uint16 a_timeout, 80 uint64& a_files_total, 81 uint64& a_files_xferd, 82 uint64& a_size_total, 83 uint64& a_size_xferd, 84 bool& a_overflow_detected 85 ); 86 void mf_parse_rsync_io( 87 std::string a_str, 88 uint64& a_files_total, 89 uint64& a_files_xferd, 90 uint64& a_size_total, 91 uint64& a_size_xferd 92 ); 93 void mf_trim_string(std::string& a_str); 94 void mf_parse_report(const std::string& a_str); 95 }; 96 97 /** Create (or update an existing) archive in the selected vault */ 98 class archive_manager { 99 public: 100 archive_manager(); 101 102 void clear(void); 103 void init(void); 104 const bool initialized(void) const; 105 106 void archive(void); 107 108 const std::string archive_path(void) const; 109 const std::string working_archive_path(void) const; 110 111 private: 112 std::vector<job_archiver*> m_jobs; 113 bool m_initialized; 114 115 void mf_log_status(void); 116 }; 117 118 extern archive_manager archiver; 119 120 #endif 121