protected function createBkFile()
    {
        if (!is_writable(dirname($this->filePath))) {
            return;
        }
        
        $this->bkFilePath = $this->filePath . '.' . date("y-m-d-H-i-s") . '.bak';
        $bkHandle = @fopen($this->bkFilePath, 'x+');
        if ($bkHandle === false) {
            $this->close();
            throw new \RuntimeException("Could not create a temporary file " . $this->bkFilePath);
        }
        $stat = fstat($this->handle);
        if (stream_copy_to_stream($this->handle, $bkHandle) !== $stat['size']) {
            $this->close();
            throw new \RuntimeException("Could not create a copy of " . $this->filePath);
        }
        
        if (!fclose($bkHandle)) {
            throw new \RuntimeException("Could not close a backup file " . $this->bkFilePath);
        }
        
        fseek($this->handle, 0);
    }