def mountFileServer(): if not MountServer.isPathMount(autoOtainfo.LocalDir): mount = Mount(autoOtainfo.LocalDir, autoOtainfo.Server, autoOtainfo.UserName, autoOtainfo.Password) return mount.doMount() else: return True
def unmount_obj(path, cid, driver): """ unmount the given path """ # If using device mapper, unmount the bind-mount over the directory if driver == 'devicemapper': Mount.unmount_path(path) DockerMount(path).unmount(cid)
def close(self): try: logger.debug("Closing Id %s On %s" % (self.image_id, self.mount_point)) # If using device mapper, unmount the bind-mount over the directory if self.driver == 'devicemapper': Mount.unmount_path(self.mount_point) DockerMount(self.mount_point).unmount(self.cid) except Exception as e: logger.debug("exception while unmounting image or container: %s" % e) shutil.rmtree(self.mount_point, ignore_errors=True)
def unmount_obj(path, driver): """ unmount the given path """ dev = DockerMount.get_dev_at_mountpoint(path) # If there's a bind-mount over the directory, unbind it. if dev.rsplit('[', 1)[-1].strip(']') == '/rootfs' \ and driver == 'devicemapper': Mount.unmount_path(path) DockerMount(path).unmount()
def add_mount(self, source, destination, opts=[]): """Associate a mount with this partition Automatically mounts it :param str,AbstractPartition source: The source of the mount :param str destination: The path to the mountpoint :param list opts: Any options that should be passed to the mount command """ # Create a new mount object, mount it if the partition is mounted and put it in the mounts dict from mount import Mount mount = Mount(source, destination, opts) if self.fsm.current == 'mounted': mount.mount(self.mount_dir) self.mounts[destination] = mount
def force_clean(cid, client, emu): """ force unmounts and removes any block devices to prevent memory corruption """ driver = client.info()['Driver'] emu.unmount(force=True) # unmount path Mount.unmount_path(emu.tmp_image_dir,force=True) # if device mapper, do second unmount and remove device if driver == 'devicemapper': Mount.unmount_path(emu.tmp_image_dir,force=True) device = client.inspect_container(cid)['GraphDriver']['Data']['DeviceName'] Mount.remove_thin_device(device,force=True)
def test_mount_class(self): filesystem = "/dev" mount = Mount(filesystem) self.assertTrue(mount.filesystem == filesystem)
lorica = Armor('Lorica', 500, 2, 7, 0.50) byrnie = Armor('Byrnie', 600, 1.7, 8, 0.75, heavy=True) brigandine = Armor('Brigandine', 1500, 2, 11, 0.25) corrazina = Armor('Corrazina', 1600, 2, 11, 0.50, heavy=True) scale_armor = Armor('Scale Armor', 1800, 1.5, 12, 0, heavy=True) coat_plate = Armor('Coat of Plates', 1900, 2, 11, 0.25, heavy=True) cuir_bouilli = Armor('Cuir Bouilli', 1700, 2, 9, 0.45, heavy=True) armor_list = [lorica, byrnie, brigandine, corrazina, scale_armor, coat_plate, cuir_bouilli, tunic, robe, fur_coat, jerkin, linen_shirt, aketon, tabard, ragged_armor, tribal_wrappings, gambeson, hauberk, lamellar, cloth_armor, padded_armor, leather_armor, wood_armor, chainmail, plate] basic_armor_list = [tunic, robe, fur_coat, jerkin, linen_shirt, aketon, tabard, ragged_armor, tribal_wrappings, gambeson, cloth_armor, leather_armor, wood_armor, padded_armor] mount_none = Mount('None', 0, 0, 0, 0, 0, 0) camel = Mount('Camel', 200, 5 / 2, 1, 0, 0.2, 0.2) donkey = Mount('Donkey', 100, 3 / 2, 0, 1, 0.1, 0.3) rouncey = Mount('Rouncey', 300, 6 / 2, 1, 1, 0.2, 0.1) horse = Mount('Donkey', 400, 7 / 2, 3, 1, 0.2, 0.2) destrier = Mount('Destrier', 500, 8 / 2, 1, 3, 0.3, 0.3) courser = Mount('Courser', 600, 10 / 2, 2, 1, 0.4, 0.3) cataphract = Mount('Cataphract', 1200, 4 / 2, 2, 5, 0.5, 1.3, heavy=True) charger = Mount('Charger', 1500, 7 / 2, 5, 2, 1.4, 0.4, heavy=True) warhorse = Mount('Warhorse', 1300, 5 / 2, 3, 3, 1.4, 1.3, heavy=True) barded_warhorse = Mount('Barded Warhorse', 1800, 4 / 2, 2, 4, 1.3, 1.4, heavy=True) elephant = Mount('Elephant', 2000, 3 / 2, 7, 7, 1.8, 2.3, heavy=True) basic_mount_list = [camel, donkey, rouncey, horse] mount_list = [camel, donkey, rouncey, horse, destrier, courser, cataphract, charger, warhorse, barded_warhorse,
def main(): main_file_exec_path = os.path.realpath(sys.argv[0]) working_dir = os.path.dirname(main_file_exec_path) config_file = working_dir + "/config/noe/noe.conf" config = Config(config_file) backup = Backup() mount = Mount() command_exec = Services() log = Log() mail = Mail() sections = config.get_sections_config() log_file = log.get_log_file() os.system("echo > {0}".format(log_file)) local_sync_onedrive_flag = 0 send_file_onedrive_flag = 0 log.log("Iniciando backup") config.set_enable_stop_services('DEFAULT', 'enable_stop_services') config.set_command_stop('DEFAULT', 'command_services_stop') config.set_command_start('DEFAULT', 'command_services_start') config.set_server_name('DEFAULT', 'server_name') enable_stop_services = config.get_enable_stop_services() command_stop = config.get_command_stop().split(',') command_start = config.get_command_start().split(',') if enable_stop_services == "yes": log.log("Parando serviços") for command in command_stop: command_exec.stop_service(command) for section in sections: if section == 'DEFAULT': continue log.log("Executando backup: " + section) config.set_type_config(section, 'type_backup') config.set_folder_config(section, 'folder_backup') config.set_folder_dest_config(section, 'folder_dest') config.set_time_keep(section, 'time_keep') config.set_remote_share_config(section, 'remote_share') config.set_host_config(section, 'host') config.set_user_config(section, 'user') config.set_password_config(section, 'password') config.set_database(section, 'database') config.set_bucket_name_config(section, 'bucket_name') config.set_access_key_config(section, 'access_key') config.set_secret_access_key(section, 'secret_access_key') config.set_file_name_config(section, date.today()) config.set_exclude_list_file(section, 'exclude_list_file') type_backup = config.get_type_config() folder_backup = config.get_folder_config() folder_dest = config.get_folder_dest_config() time_keep = config.get_time_keep() remote_share = config.get_remote_share_config() host = config.get_host_config() user = config.get_user_config() password = config.get_password_config() database = config.get_database() bucket_name = config.get_bucket_name_config() access_key = config.get_access_key_config() secret_access_key = config.get_secret_access_key() filename = config.get_file_name_config() exclude_list_file = config.get_exclude_list_file() if not os.path.isdir(folder_dest): os.mkdir(folder_dest) os.system("tmpreaper {0} {1}".format(time_keep, folder_dest)) if type_backup == "local": log.log("Backup do tipo local") log.log("Executando cópia e compressão dos arquivos") backup.run(exclude_list_file, folder_dest, filename, folder_backup) log.log("Fim do backup " + section) elif type_backup == "local-sync-onedrive": log.log("Backup do tipo local-sync-onedrive") log.log("Executando a cópia e compressão dos arquivos") backup.run(exclude_list_file, folder_dest, filename, folder_backup) log.log("Fim do backup " + section) local_sync_onedrive_flag = 1 elif type_backup == "send-file-onedrive": log.log("Backup do tipo send-file-onedrive") backup.run(exclude_list_file, folder_dest, filename, folder_backup) log.log("Fim do backup " + section) send_file_onedrive_flag = 1 elif type_backup == "samba": log.log("Executando backup do tipo samba") log.log("Montando compartilhamento") mount.mountSamba(host, remote_share, folder_dest, user, password) log.log("Executando cópia e compressão dos arquivos") backup.run(exclude_list_file, folder_dest, filename, folder_backup) log.log("Fim do backup " + section) log.log("Desmontando compartilhamento") mount.umount(folder_dest) elif type_backup == "bucket": tmp_file = "/tmp/.passwd-s3fs" log.log("Montando o bucket") mount.mountBucket(access_key, secret_access_key, tmp_file, bucket_name, folder_dest) log.log("Executando a cópia e compactação dos arquivos") backup.run(exclude_list_file, folder_dest, filename, folder_backup) log.log("Demontando bucket") mount.umount(folder_dest) elif type_backup == "mysql": log.log("Executando backup do banco de dados") os.system("mysqldump -u {0} -p{1} {2} -h {3} > {4}/{5}.sql".format( user, password, database, host, folder_dest, filename )) os.system("tar -zcvf {0}/{1}.tar.gz {0}/{1}.sql".format(folder_dest, filename)) os.system("rm {0}/{1}.sql".format(folder_dest, filename)) log.log("Backup do banco de dados concluído") else: print("Tipo de backup não válido") if enable_stop_services == "yes": log.log("Subindo serviços") for command in command_start: command_exec.start_service(command) if local_sync_onedrive_flag == 1: log.log("Sincronizando pasta de backup com a nuvem") folder_sync_onedrive = os.path.basename(folder_dest) os.system("onedrive --synchronize --upload-only --no-remote-delete") os.system("onedrive --synchronize --single-directory '{0}'".format(folder_sync_onedrive)) log.log("Envio concluído") elif send_file_onedrive_flag == 1: log.log("Enviando backup via upload para o onedrive") os.system("onedrive --synchronize --upload-only --no-remote-delete") log.log("Envio concluído") config.set_mail_address('DEFAULT', 'mail_address') mail_address = config.get_mail_address() server_name = config.get_server_name() if mail_address: log.log("Enviando E-mail") mail.send("Backup NOE - {0}".format(server_name), mail_address)
def __init__(self): super(Main, self).__init__(load_config, NAME_FILE_CONFIG_PATH, NAME_FILE_LOG_PATH) self.loading_args() self.log_configuration() # General self.config = self.loading_file_config() self.errors = [] self.fecha = str(datetime.date.today()) self.hora_inicio = str(time.strftime("%H-%M-%S")) self.numbers_backup = self.config.get("GENERAL", "numbers_backup") self.ruta_destino = Path(self.config.get("GENERAL", "destiny_path")) # Mount and unmount self.mount_is_enable = self.config.get("MOUNT", "enable") == "yes" self.umount_is_enable = self.config.get("MOUNT", "umount") == "yes" self.username_und = self.config.get("MOUNT", "username_und") self.password_und = self.config.get("MOUNT", "password_und") self.path_network = self.config.get("MOUNT", "path_network") self.letter_und = self.config.get("MOUNT", "letter_und") self.mount = Mount(self.errors, self.mount_is_enable, self.umount_is_enable, self.username_und, self.password_und, self.path_network, self.letter_und, self.ruta_destino) # Run command mount und network errors, salida_error_cmd, salida_cmd = self.mount.fun_mount_und() self.errors = errors # Backups self.backup = Backup(self.config, self.errors) self.command_backup = self.backup.gen_command_backup( self.config, self.fecha, self.hora_inicio) self.name_file_backup_latest = self.backup.gen_name_file_backup_latest( self.config, self.fecha, self.hora_inicio) # gen path temp Backup self.path_name_temp = self.ruta_destino.child( self.name_file_backup_latest) size_dump_file = 0 # Is not errors in mounting if not self.errors: result = self.backup.run_command_backup( self.config, self.command_backup, self.numbers_backup, self.path_name_temp, self.ruta_destino, ) size_dump_file = result.size self.errors = result.err full_path_dump = self.ruta_destino + "/sql-0/" + self.name_file_backup_latest # unmount if mount self.mount.fun_umount() hora_final = time.strftime("%H-%M-%S") report = gen_report(self.fecha, self.hora_inicio, hora_final, full_path_dump, size_dump_file, self.errors) # Function send notification. mail = Mail(self.config, NAME_FILE_LOG_PATH) mail.fun_send_mail(report) logging.info("Script Completado.")