| Lines 1019-1030
          def backup_secrets(self, private_dir, lp, logger):
      
      
        Link Here | 
        
          | 1019 |  | 1019 |  | 
        
          | 1020 |     # sam.ldb must have a transaction started on it before backing up | 1020 |     # sam.ldb must have a transaction started on it before backing up | 
        
          | 1021 |     # everything in sam.ldb.d with the appropriate backup function. | 1021 |     # everything in sam.ldb.d with the appropriate backup function. | 
            
              | 1022 |     # |  |  | 
            
              | 1023 |     # Obtains the sidForRestore (SID for the new DC) and returns it | 
            
              | 1024 |     # from under the transaction | 
        
          | 1025 |     def backup_smb_dbs(self, private_dir, samdb, lp, logger): | 1022 |     def backup_smb_dbs(self, private_dir, samdb, lp, logger): | 
            
              | 1026 |         sam_ldb_path = os.path.join(private_dir, 'sam.ldb') |  |  | 
            
              | 1027 |  | 
        
          | 1028 |         # First, determine if DB backend is MDB.  Assume not unless there is a | 1023 |         # First, determine if DB backend is MDB.  Assume not unless there is a | 
        
          | 1029 |         # 'backendStore' attribute on @PARTITION containing the text 'mdb' | 1024 |         # 'backendStore' attribute on @PARTITION containing the text 'mdb' | 
        
          | 1030 |         store_label = "backendStore" | 1025 |         store_label = "backendStore" | 
  
    | Lines 1032-1055
          def backup_smb_dbs(self, private_dir, samdb, lp, logger):
      
      
        Link Here | 
        
          | 1032 |                            attrs=[store_label]) | 1027 |                            attrs=[store_label]) | 
        
          | 1033 |         mdb_backend = store_label in res[0] and str(res[0][store_label][0]) == 'mdb' | 1028 |         mdb_backend = store_label in res[0] and str(res[0][store_label][0]) == 'mdb' | 
        
          | 1034 |  | 1029 |  | 
          
            
              | 1035 |         # This is needed to keep this variable in scope until the end | 1030 |         sam_ldb_path = os.path.join(private_dir, 'sam.ldb') | 
            
              | 1036 |         # of the transaction. |  |  | 
            
              | 1037 |         res_iterator = None | 
            
              | 1038 |  | 
        
          | 1039 |         copy_function = None | 1031 |         copy_function = None | 
        
          | 1040 |         if mdb_backend: | 1032 |         if mdb_backend: | 
        
          | 1041 |             logger.info('MDB backend detected.  Using mdb backup function.') | 1033 |             logger.info('MDB backend detected.  Using mdb backup function.') | 
        
          | 1042 |             copy_function = self.offline_mdb_copy | 1034 |             copy_function = self.offline_mdb_copy | 
            
              | 1043 |  |  |  | 
            
              | 1044 |             # We can't backup with a write transaction open, so get a | 
            
              | 1045 |             # read lock with a search_iterator(). | 
            
              | 1046 |             # | 
            
              | 1047 |             # We have tests in lib/ldb/tests/python/api.py that the | 
            
              | 1048 |             # search iterator takes a read lock effective against a | 
            
              | 1049 |             # transaction.  This in turn will ensure there are no | 
            
              | 1050 |             # transactions on either the main or sub-database, even if | 
            
              | 1051 |             # the read locks were not enforced globally (they are). | 
            
              | 1052 |             res_iterator = samdb.search_iterator() | 
        
          | 1053 |         else: | 1035 |         else: | 
        
          | 1054 |             logger.info('Starting transaction on ' + sam_ldb_path) | 1036 |             logger.info('Starting transaction on ' + sam_ldb_path) | 
        
          | 1055 |             copy_function = self.offline_tdb_copy | 1037 |             copy_function = self.offline_tdb_copy | 
  
    | Lines 1070-1085
          def backup_smb_dbs(self, private_dir, samdb, lp, logger):
      
      
        Link Here | 
        
          | 1070 |                 logger.info('   copying locked/related file ' + sam_file) | 1052 |                 logger.info('   copying locked/related file ' + sam_file) | 
        
          | 1071 |                 shutil.copyfile(sam_file, sam_file + self.backup_ext) | 1053 |                 shutil.copyfile(sam_file, sam_file + self.backup_ext) | 
        
          | 1072 |  | 1054 |  | 
          
            
              | 1073 |         sid = get_sid_for_restore(samdb, logger) | 1055 |         if not mdb_backend: | 
            
              | 1074 |  |  |  | 
            
              | 1075 |         if mdb_backend: | 
            
              | 1076 |             # Delete the iterator, release the read lock | 
            
              | 1077 |             del(res_iterator) | 
            
              | 1078 |         else: | 
        
          | 1079 |             samdb.transaction_cancel() | 1056 |             samdb.transaction_cancel() | 
        
          | 1080 |  | 1057 |  | 
            
              | 1081 |         return sid |  |  | 
            
              | 1082 |  | 
        
          | 1083 |     # Find where a path should go in the fixed backup archive structure. | 1058 |     # Find where a path should go in the fixed backup archive structure. | 
        
          | 1084 |     def get_arc_path(self, path, conf_paths): | 1059 |     def get_arc_path(self, path, conf_paths): | 
        
          | 1085 |         backup_dirs = {"private": conf_paths.private_dir, | 1060 |         backup_dirs = {"private": conf_paths.private_dir, | 
  
    | Lines 1170-1186
          def run(self, sambaopts=None, targetdir=None):
      
      
        Link Here | 
        
          | 1170 |         samdb = SamDB(url=paths.samdb, session_info=system_session(), lp=lp, | 1145 |         samdb = SamDB(url=paths.samdb, session_info=system_session(), lp=lp, | 
        
          | 1171 |                       flags=ldb.FLG_DONT_CREATE_DB) | 1146 |                       flags=ldb.FLG_DONT_CREATE_DB) | 
        
          | 1172 |  | 1147 |  | 
            
              | 1173 |         # Backup secrets, sam.ldb and their downstream files |  |  | 
        
          | 1174 |         self.backup_secrets(paths.private_dir, lp, logger) | 1148 |         self.backup_secrets(paths.private_dir, lp, logger) | 
          
            
              | 1175 |         sid = self.backup_smb_dbs(paths.private_dir, samdb, lp, logger) | 1149 |         self.backup_smb_dbs(paths.private_dir, samdb, lp, logger) | 
        
          | 1176 |  | 1150 |  | 
        
          | 1177 |         # Get the domain SID so we can later place it in the backup | 1151 |         # Get the domain SID so we can later place it in the backup | 
        
          | 1178 |         dom_sid_str = samdb.get_domain_sid() | 1152 |         dom_sid_str = samdb.get_domain_sid() | 
        
          | 1179 |         dom_sid = security.dom_sid(dom_sid_str) | 1153 |         dom_sid = security.dom_sid(dom_sid_str) | 
        
          | 1180 |  | 1154 |  | 
          
            
              | 1181 |         # Close the original samdb, to avoid any confusion, we will | 1155 |         sid = get_sid_for_restore(samdb, logger) | 
            
              | 1182 |         # not use this any more as the data has all been copied under | 1156 |  | 
            
              | 1183 |         # the transaction | 1157 |         # Close the original samdb | 
        
          | 1184 |         samdb = None | 1158 |         samdb = None | 
        
          | 1185 |  | 1159 |  | 
        
          | 1186 |         # Open the new backed up samdb, flag it as backed up, and write | 1160 |         # Open the new backed up samdb, flag it as backed up, and write | 
            
              | 1187 | -  |  |  | 
        
          | 1188 | samdb when backing up sam.ldb" | 1161 | samdb when backing up sam.ldb" | 
            
              | 1189 | -- |  |  | 
        
          | 1190 | python/samba/netcmd/domain/backup.py | 15 +++++++-------- | 1162 | python/samba/netcmd/domain/backup.py | 15 +++++++-------- | 
        
          | 1191 | 1 file changed, 7 insertions(+), 8 deletions(-) | 1163 | 1 file changed, 7 insertions(+), 8 deletions(-) |