Perform backup action on set driver

    :param file: Name of the file to be used by the driver
    :param host: Corresponding host name associated with file
172104
def backup_file(*, file, host):
    
    if _driver:
        log.msg_debug("[{driver}] Backing up file '{file}'"
                      .format(driver=_driver.get_name(), file=file))
        _driver.backup_file(file=file, host=host)
809391
def copy_file(file_name):
	

	remote_file_path = join(join(expanduser('~'), OCTOGRID_DIRECTORY), file_name)
	current_path = join(getcwd(), file_name)

	try:
		copyfile(remote_file_path, current_path)
	except Exception, e:
		raise e
1015639
def send_file_to_host(src_filename, dst_file, filesize):
    """"""
    import sys
    import ubinascii
    try:
        with open(src_filename, 'rb') as src_file:
            bytes_remaining = filesize
            if HAS_BUFFER:
                buf_size = BUFFER_SIZE
            else:
                buf_size = BUFFER_SIZE // 2
            while bytes_remaining > 0:
                read_size = min(bytes_remaining, buf_size)
                buf = src_file.read(read_size)
                if HAS_BUFFER:
                    sys.stdout.buffer.write(buf)
                else:
                    sys.stdout.write(ubinascii.hexlify(buf))
                bytes_remaining -= read_size
                # Wait for an ack so we don't get ahead of the remote
                while True:
                    char = sys.stdin.read(1)
                    if char:
                        if char == '\x06':
                            break
                        # This should only happen if an error occurs
                        sys.stdout.write(char)
        return True
    except:
        return False
1280887
void backup() throws ConfigurationPersistenceException {
        if (!doneBootup.get()) {
            return;
        }
        try {
            if (!interactionPolicy.isReadOnly()) {
                //Move the main file to the versioned history
                moveFile(mainFile, getVersionedFile(mainFile));
            } else {
                //Copy the Last file to the versioned history
                moveFile(lastFile, getVersionedFile(mainFile));
            }
            int seq = sequence.get();
            // delete unwanted backup files
            int currentHistoryLength = getInteger(CURRENT_HISTORY_LENGTH_PROPERTY, CURRENT_HISTORY_LENGTH, 0);
            if (seq > currentHistoryLength) {
                for (int k = seq - currentHistoryLength; k > 0; k--) {
                    File delete = getVersionedFile(mainFile, k);
                    if (! delete.exists()) {
                        break;
                    }
                    delete.delete();
                }
            }
        } catch (IOException e) {
            throw ControllerLogger.ROOT_LOGGER.failedToBackup(e, mainFile);
        }
    }
1173309
def makeBackupFile(outFile)
      backupFileName = outFile+"~"
      if File.exists? backupFileName
        puts "BACKUP: deleting existing backup file #{backupFileName} ..."
        File.delete (backupFileName)
      end
      if File.exists? outFile
        puts "BACKUP: renaming file #{outFile} to #{backupFileName} ..."
        File.rename(outFile, backupFileName)
      end
      backupFileName
    end
24179
@Override
    public void setFile(File file) {
        configFile = file;
        if (tc.isDebugEnabled())
            Tr.debug(tc, "Jaspi configuration of persistent providers will be stored in file: " + file);
    }
119551
def copyfile(source, dest, backup_mode='', cachedir=''):
    '''
    
    '''
    if not os.path.isfile(source):
        raise IOError(
            '[Errno 2] No such file or directory: {0}'.format(source)
        )
    if not os.path.isdir(os.path.dirname(dest)):
        raise IOError(
            '[Errno 2] No such file or directory: {0}'.format(dest)
        )
    bname = os.path.basename(dest)
    dname = os.path.dirname(os.path.abspath(dest))
    tgt = mkstemp(prefix=bname, dir=dname)
    shutil.copyfile(source, tgt)
    bkroot = ''
    if cachedir:
        bkroot = os.path.join(cachedir, 'file_backup')
    if backup_mode == 'minion' or backup_mode == 'both' and bkroot:
        if os.path.exists(dest):
            backup_minion(dest, bkroot)
    if backup_mode == 'master' or backup_mode == 'both' and bkroot:
        # TODO, backup to master
        pass
    # Get current file stats to they can be replicated after the new file is
    # moved to the destination path.
    fstat = None
    if not salt.utils.platform.is_windows():
        try:
            fstat = os.stat(dest)
        except OSError:
            pass

    # The move could fail if the dest has xattr protections, so delete the
    # temp file in this case
    try:
        shutil.move(tgt, dest)
    except Exception:
        __clean_tmp(tgt)
        raise

    if fstat is not None:
        os.chown(dest, fstat.st_uid, fstat.st_gid)
        os.chmod(dest, fstat.st_mode)
    # If SELINUX is available run a restorecon on the file
    rcon = salt.utils.path.which('restorecon')
    if rcon:
        policy = False
        try:
            policy = salt.modules.selinux.getenforce()
        except (ImportError, CommandExecutionError):
            pass
        if policy == 'Enforcing':
            with fopen(os.devnull, 'w') as dev_null:
                cmd = [rcon, dest]
                subprocess.call(cmd, stdout=dev_null, stderr=dev_null)
    if os.path.isfile(tgt):
        # The temp file failed to move
        __clean_tmp(tgt)
633102
def copy_file(src, target):
    
    LOGGER.info("Copying {} to {}".format(src, target))
    shutil.copyfile(src, target)
    shutil.copymode(src, target)
237685
def write_tree_file(tree, hostname, buf):
    '''  '''

    # TODO: might be nice to append playbook runs per host in a similar way
    # in which case, we'd want append mode.
    path = os.path.join(tree, hostname)
    fd = open(path, "w+")
    fd.write(buf)
    fd.close()
1350781
def rollback(self):
        
        if self.changed:
            rollback_cmd = '<load><config><from>{0}</from></config></load>'.format(self.backup_file)
            self.device.op(cmd=rollback_cmd)
            time.sleep(5)

            if self.ssh_connection is False:
                self._open_ssh()
            try:
                self.ssh_device.commit()
                self.loaded = False
                self.changed = False
                self.merge_config = False
            except:    # noqa
                ReplaceConfigException("Error while loading backup config")
688527
def copy_file(self, from_path, to_path, replace=False):
        
        f = self.get_file(from_path)
        if f.copy(to_path, replace):
            self.set_cache_buster(to_path, f.hash())
190184
def write(self, file):
        
        render(
            self.template,
            file,
            benchmarks=self.benchmarks,
            hostname=socket.gethostname(),
        )
838760
def save(file)
      path = case file
        when :global then GLOBAL_CONFS.first
        when :user then USER_CONFS.first
        else Pathname.new(file)
      end

      raise JSS::MissingDataError, "No HOME environment variable, can't write to user conf file." if path.nil?

      # file already exists? read it in and update the values.
      if path.readable?
        data = path.read

        # go thru the known attributes/keys
        CONF_KEYS.keys.sort.each do |k|

          # if the key exists, update it.
          if data =~ /^#{k}:/
            data.sub!(/^#{k}:.*$/, "#{k}: #{self.send k}")

          # if not, add it to the end unless it's nil
          else
            data += "\n#{k}: #{self.send k}" unless self.send(k).nil?
          end # if data =~ /^#{k}:/
        end #each do |k|

      else # not readable, make a new file
        data = ""
        CONF_KEYS.keys.sort.each do |k|
          data << "#{k}: #{self.send k}\n" unless self.send(k).nil?
        end
      end # if path readable

      # make sure we end with a newline, the save it.
      data << "\n" unless data.end_with?("\n")
      path.jss_save data
    end
1260245
def store_to_file(self, filename):
    
    with tf.gfile.Open(filename, "w") as f:
      for i in range(len(self._id_to_token)):
        f.write(self._id_to_token[i] + "\n")
785670
def update_hosts_file(self, ip, entry):
        
        log = logging.getLogger(self.cls_logger + '.update_hosts_file')

        if get_os() in ['Linux', 'Darwin']:
            update_hosts_file_linux(ip=ip, entry=entry)
        elif get_os() == 'Windows':
            update_hosts_file_windows(ip=ip, entry=entry)
        else:
            log.warn('OS detected was not Windows nor Linux')
15767
def send_file(self, file):
        
        if self.logger:
            self.logger.debug("[ioc.extra.tornado.RouterHandler] send file %s" % file)

        self.send_file_header(file)

        fp = open(file, 'rb')
        self.write(fp.read())

        fp.close()
1200
def load_known_hosts(self, filename=None):

        

        if filename is None:
            filename = os.path.expanduser('~/.ssh/known_hosts')
            try:
                self._host_keys.load(filename)
            except IOError:
                # for windows
                filename = os.path.expanduser('~/ssh/known_hosts')
                try:
                    self._host_keys.load(filename)
                except IOError:
                    pass
        else:
            self._host_keys.load(filename)