Changeset 40911 for branches/ipp-259_genericise_backups/tools/backups/backup_atlassian_applications.py
- Timestamp:
- Oct 4, 2019, 12:03:16 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-259_genericise_backups/tools/backups/backup_atlassian_applications.py
r40898 r40911 10 10 11 11 import backups.utils.subprocess_utils as sub_utils 12 import backups.utils.generic_utils as gen_utils 12 13 from backups.utils.errors import ConfigError, SubprocessError 13 14 14 15 DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'atlassian_backups.config') 15 16 17 def _move_dir_contents_to_dir(source_dirs: [str], destination_dirs: [str], verbose: bool=False):18 """ Moves all files from inside source paths to the destination dits.19 It's important to note that it moves index to index20 i.e. source[0] -> dest[0]; source[1] -> dest[1]21 22 This is actually a pretty generic function, should be moved into a utils class.23 """24 25 if source_dirs is None or destination_dirs is None:26 print("Error: You need to supply a source and destination")27 return 228 if type(source_dirs) != list or type(destination_dirs) != list:29 print("Error: source_dirs and destination_dirs must be type: list")30 print(" type {0} and {1} given".format(type(source_dirs), type(destination_dirs)))31 return 232 if len(source_dirs) != len(destination_dirs):33 print("Error: source and target paths are not equal; aborting file movement")34 return 235 36 for i in range(0, len(source_dirs)):37 # Identify files in path, move each one:38 wildcard_search = "{0}/*".format(source_dirs[i])39 filepaths = glob.glob(wildcard_search)40 if len(filepaths) == 0:41 print("Warning: directory is empty: ", source_dirs[i])42 continue43 try:44 for fp in filepaths:45 if verbose:46 print("Moving: {0} -> {1}".format(fp, destination_dirs[i]))47 command_and_args = ["mv", fp, destination_dirs[i]]48 # shutil.move(fp, destination_dirs[i])49 sub_utils.simple_unix_wrapper(command_and_args)50 except IOError as e:51 print("IOError copying: ", e.filename, e.filename2)52 return 253 54 return 055 16 56 17 … … 129 90 130 91 # Move latest to tmp (and delete if move ok) 131 _move_dir_contents_to_dir(latest_paths, tmp_paths, self.verbose)92 gen_utils.copy_multiple_items_to_multiple_dirs(latest_paths, tmp_paths, self.verbose) 132 93 133 94 # copy jira … … 145 106 # If successful: move tmp to old 146 107 if jira_return == 0 and conf_return == 0 and tar_return == 0 and mysqldump_return == 0: 147 _move_dir_contents_to_dir(tmp_paths, old_paths, self.verbose)108 gen_utils.copy_multiple_items_to_multiple_dirs(tmp_paths, old_paths, self.verbose) 148 109 else: 149 110 # If any failed: delete latest, move tmp back 150 _move_dir_contents_to_dir(tmp_paths, latest_paths, self.verbose)111 gen_utils.copy_multiple_items_to_multiple_dirs(tmp_paths, latest_paths, self.verbose) 151 112 return 5 152 113
Note:
See TracChangeset
for help on using the changeset viewer.
