Changeset 40892 for branches/ipp-132_automate_jira_conf_backups/backups/backup_atlassian_applications.py
- Timestamp:
- Sep 20, 2019, 4:01:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-132_automate_jira_conf_backups/backups/backup_atlassian_applications.py
r40885 r40892 6 6 import os.path as path 7 7 import shutil 8 import subprocess 8 9 import sys 9 10 … … 29 30 30 31 DEFAULT_VERBOSITY = False 32 33 34 class SubprocessError(Exception): 35 """Errors in Popen stderr subprocess""" 31 36 32 37 … … 198 203 # If any failed: delete latest, move tmp back 199 204 _move_dir_contents_to_dir(tmp_paths, latest_paths) 205 return 5 200 206 201 207 # TODO:clean-up old files (to save space) … … 290 296 return 0 291 297 292 def make_mysql_dump(self ):298 def make_mysql_dump(self, dump_password, dump_name=None): 293 299 # do this as the dumper user 294 300 301 latest_paths = self.target_paths("latest") 302 if not self.target_backup_paths_ok(): 303 return 1 304 295 305 # make sure target file does not exist (or it will fail) 296 297 # verify mysql checksum? 306 if dump_name is None: 307 date = datetime.date.today().strftime("%Y_%m_%d") 308 dump_filepath = path.join(latest_paths[0], '{0}_mysql_dump.sql'.format(date)) 309 else: 310 dump_filepath = path.join(latest_paths[0], dump_name) 311 if path.exists(dump_filepath): 312 print("Warning: SQL dump already exists: ", dump_filepath) 313 return 2 314 315 # Setup the commands: 316 mysqldump_args = [ 'mysqldump', '-u', 'dumper', '-p{0}'.format(dump_password) 317 , '--databases', 'jiradb', 'confluencedb' 318 ] 319 with open(dump_filepath, "w+") as df: 320 mysqldump_process = subprocess.Popen(mysqldump_args, stdout=df, stderr=subprocess.PIPE) 321 dump_result = mysqldump_process.communicate() 322 323 # Get the piped std err. See it contains the word error 324 stdo, stde = dump_result 325 if stde is not None: 326 decoded_stderr = stde.decode() 327 if decoded_stderr.casefold().find('error'.casefold()) > -1: 328 raise SubprocessError() 298 329 299 330 # move the dump file to the correct locations 331 if not path.exists(dump_filepath): 332 return 2 333 cp_1 = sub_utils.cp_wrapper([dump_filepath, latest_paths[1]]) 334 cp_2 = sub_utils.cp_wrapper([dump_filepath, latest_paths[2]]) 335 if cp_1 != 0: 336 return cp_1 337 if cp_2 != 0: 338 return cp_2 300 339 return 0 301 340
Note:
See TracChangeset
for help on using the changeset viewer.
