Function: Move the directory to a backup location
(module_id)
| 6 | global logger, timer_start_dict, timer_end_dict, download_status |
| 7 | |
| 8 | def make_backup(module_id): |
| 9 | """ Function: Move the directory to a backup location |
| 10 | """ |
| 11 | backup_location = config.find_location_for_module(module_id, 'backup_location') |
| 12 | stage_location = config.find_location_for_module(module_id, 'stage_location') |
| 13 | logger.info("["+module_id+"] Moving files " + stage_location + " to " + backup_location ) |
| 14 | try: |
| 15 | if os.path.exists(backup_location): |
| 16 | shutil.rmtree( backup_location, True ) |
| 17 | else: |
| 18 | #This is to ensure that backup folder's path exists |
| 19 | #and this path is reachable |
| 20 | os.makedirs(backup_location) |
| 21 | shutil.rmtree(backup_location, True ) |
| 22 | if os.path.exists(stage_location): |
| 23 | shutil.move( stage_location , backup_location) |
| 24 | else: |
| 25 | logger.info("Location " + stage_location + " not present, no backup taken") |
| 26 | except: |
| 27 | logger.error("[" + module_id + "] Failed to remove:" + backup_location) |
| 28 | logger.error("[" + module_id + "] Failed to remove Error:" + str(sys.exc_info()[0])+ " " + str(sys.exc_info()[1])) |
| 29 | raise |
| 30 | else: |
| 31 | os.makedirs(stage_location) |
| 32 | |
| 33 | |
| 34 | def copy_to_machine(machine_name, module_id, config): |