The selected file to backup is invalid.

Get help with installation and running phpBB 3.2.x here. Please do not post bug reports, feature requests, or extension related questions here.
ivailo95
Registered User
Posts: 715
Joined: Tue Sep 05, 2017 8:00 am
Location: Bulgaria
Name: Ivailo
Contact:

The selected file to backup is invalid.

Post by ivailo95 » Sat Jul 06, 2019 6:57 am

i made backup as text,but it's invalid to restore why?
in previous version was valid to restor from text file backup
also invalid as gzip and bzip2.. :shock:
Attachments
Screenshot 2019-07-06 09.54.59.png

User avatar
warmweer
Registered User
Posts: 2397
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: The selected file to backup is invalid.

Post by warmweer » Sat Jul 06, 2019 8:09 am

ivailo95 wrote: ↑
Sat Jul 06, 2019 6:57 am
i made backup as text,but it's invalid to restore why?
in previous version was valid to restor from text file backup
also invalid as gzip and bzip2.. :shock:
What do you mean with "backup as text"?

As backup produced by phphbb is an SQL file which is basically a text file. It order to save space it can be compressed and then the extension would be gz (or zip). My guess is that the file you made is not recognised by phpBB as a valid backupfile. The reason for this is the header of the backup file.
Take a look at a backup made by phpBB, and use the header in the SQLs you make to fool the system into accepting the file as one made by the system itself.

BTW, you topic title is misleading: it's not the file to backup which is invalid, it's the formatting of the file which prevents it from being recognised as a restorable backup in phpbb.
My board's not broken, it just went peculiar

User avatar
3Di
Former Team Member
Posts: 13924
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: The selected file to backup is invalid.

Post by 3Di » Sat Jul 06, 2019 12:13 pm

It is fixed for 3.2.8 of phpBB:

https://github.com/phpbb/phpbb/pull/5587
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity ΒΊ PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
πŸ‘¨β€πŸ« | Take a tour to | The Studio | πŸ‘¨β€πŸ«

User avatar
warmweer
Registered User
Posts: 2397
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: The selected file to backup is invalid.

Post by warmweer » Sat Jul 06, 2019 3:30 pm

3Di wrote: ↑
Sat Jul 06, 2019 12:13 pm
It is fixed for 3.2.8 of phpBB:

https://github.com/phpbb/phpbb/pull/5587
Ah, I didn't even know about that issue. I thought he was trying to restore a backup made not made by phpbb, by restoring it using phpBB.
My board's not broken, it just went peculiar

ivailo95
Registered User
Posts: 715
Joined: Tue Sep 05, 2017 8:00 am
Location: Bulgaria
Name: Ivailo
Contact:

Re: The selected file to backup is invalid.

Post by ivailo95 » Sun Jul 07, 2019 6:58 am

3Di wrote: ↑
Sat Jul 06, 2019 12:13 pm
It is fixed for 3.2.8 of phpBB:

https://github.com/phpbb/phpbb/pull/5587
nah,i prefer do update when the official release is done. :idea:

User avatar
warmweer
Registered User
Posts: 2397
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: The selected file to backup is invalid.

Post by warmweer » Sun Jul 07, 2019 10:18 am

ivailo95 wrote: ↑
Sun Jul 07, 2019 6:58 am
nah,i prefer do update when the official release is done. :idea:
The edit is one (1) character. You might as well apply it immediately to restore that function.
My board's not broken, it just went peculiar

ivailo95
Registered User
Posts: 715
Joined: Tue Sep 05, 2017 8:00 am
Location: Bulgaria
Name: Ivailo
Contact:

Re: The selected file to backup is invalid.

Post by ivailo95 » Sun Jul 07, 2019 3:17 pm

warmweer wrote: ↑
Sun Jul 07, 2019 10:18 am
ivailo95 wrote: ↑
Sun Jul 07, 2019 6:58 am
nah,i prefer do update when the official release is done. :idea:
The edit is one (1) character. You might as well apply it immediately to restore that function.
How?


User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 50590
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: The selected file to backup is invalid.

Post by stevemaury » Sun Jul 07, 2019 3:24 pm

OPEN /includes/acp/acp_database.php

FIND, at line 219:

Code: Select all

extensions
REPLACE WITH:

Code: Select all

extension
For REALLY good and VERY inexpensive hosting CLICK HERE

I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)

User avatar
warmweer
Registered User
Posts: 2397
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Re: The selected file to backup is invalid.

Post by warmweer » Sun Jul 07, 2019 3:57 pm

ivailo95 wrote: ↑
Sun Jul 07, 2019 3:17 pm
How?
you actually quoted the solution:
3Di wrote: ↑
Sat Jul 06, 2019 12:13 pm
It is fixed for 3.2.8 of phpBB:

https://github.com/phpbb/phpbb/pull/5587
My board's not broken, it just went peculiar

ivailo95
Registered User
Posts: 715
Joined: Tue Sep 05, 2017 8:00 am
Location: Bulgaria
Name: Ivailo
Contact:

Re: The selected file to backup is invalid.

Post by ivailo95 » Sun Jul 07, 2019 9:28 pm

um..what i need to do?
to download files or?

User avatar
</Solidjeuh>
Registered User
Posts: 1689
Joined: Tue Mar 29, 2016 3:45 am
Location: Aalst (Belgium)
Name: Andy Dm
Contact:

Re: The selected file to backup is invalid.

Post by </Solidjeuh> » Sun Jul 07, 2019 9:33 pm

ivailo95 wrote: ↑
Sun Jul 07, 2019 9:28 pm
um..what i need to do?
to download files or?
Dude... read :D

viewtopic.php?f=556&t=2516006#p15284176

User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 50590
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: The selected file to backup is invalid.

Post by stevemaury » Sun Jul 07, 2019 10:50 pm

stevemaury wrote: ↑
Sun Jul 07, 2019 3:24 pm
OPEN /includes/acp/acp_database.php

FIND, at line 219:

Code: Select all

extensions
REPLACE WITH:

Code: Select all

extension
For REALLY good and VERY inexpensive hosting CLICK HERE

I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)

ivailo95
Registered User
Posts: 715
Joined: Tue Sep 05, 2017 8:00 am
Location: Bulgaria
Name: Ivailo
Contact:

Re: The selected file to backup is invalid.

Post by ivailo95 » Mon Jul 08, 2019 6:49 pm

Where is this?

Code: Select all

acp_database

Code: Select all

<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

class acp_database
{
	var $db_tools;
	var $u_action;
	public $page_title;

	function main($id, $mode)
	{
		global $cache, $db, $user, $template, $table_prefix, $request;
		global $phpbb_root_path, $phpbb_container, $phpbb_log;

		$this->db_tools = $phpbb_container->get('dbal.tools');

		$user->add_lang('acp/database');

		$this->tpl_name = 'acp_database';
		$this->page_title = 'ACP_DATABASE';

		$action	= $request->variable('action', '');

		$form_key = 'acp_database';
		add_form_key($form_key);

		$template->assign_vars(array(
			'MODE'	=> $mode,
			'S_DOWNLOAD_DATABASE'		=> ($user->data['user_id'] == 2) ? true : false,
		));

		switch ($mode)
		{
			case 'backup':

				$this->page_title = 'ACP_BACKUP';

				switch ($action)
				{
					case 'download':
						$type	= $request->variable('type', '');
						$table	= array_intersect($this->db_tools->sql_list_tables(), $request->variable('table', array('')));
						$format	= $request->variable('method', '');
						$where	= $request->variable('where', '');

						if (!count($table))
						{
							trigger_error($user->lang['TABLE_SELECT_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
						}

						if (!check_form_key($form_key))
						{
							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
						}

						$store = $download = $structure = $schema_data = false;

						if ($where == 'store_and_download' || $where == 'store')
						{
							$store = true;
						}

						if ($type == 'full' || $type == 'structure')
						{
							$structure = true;
						}

						if ($where == 'store_and_download' || ($where == 'download' && $user->data['user_id'] == 2))
						{
							$download = true;
						}

						if ($type == 'full' || $type == 'data')
						{
							$schema_data = true;
						}

						@set_time_limit(1200);
						@set_time_limit(0);

						$time = time();

						$filename = 'backup_' . $time . '_' . unique_id();

						/** @var phpbb\db\extractor\extractor_interface $extractor Database extractor */
						$extractor = $phpbb_container->get('dbal.extractor');
						$extractor->init_extractor($format, $filename, $time, $download, $store);

						$extractor->write_start($table_prefix);

						foreach ($table as $table_name)
						{
							// Get the table structure
							if ($structure)
							{
								$extractor->write_table($table_name);
							}
							else
							{
								// We might wanna empty out all that junk :D
								switch ($db->get_sql_layer())
								{
									case 'sqlite3':
										$extractor->flush('DELETE FROM ' . $table_name . ";\n");
									break;

									case 'mssql_odbc':
									case 'mssqlnative':
										$extractor->flush('TRUNCATE TABLE ' . $table_name . "GO\n");
									break;

									case 'oracle':
										$extractor->flush('TRUNCATE TABLE ' . $table_name . "/\n");
									break;

									default:
										$extractor->flush('TRUNCATE TABLE ' . $table_name . ";\n");
									break;
								}
							}

							// Data
							if ($schema_data)
							{
								$extractor->write_data($table_name);
							}
						}

						$extractor->write_end();

						$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_BACKUP');

						if ($download == true)
						{
							exit;
						}

						trigger_error($user->lang['BACKUP_SUCCESS'] . adm_back_link($this->u_action));
					break;

					default:
						$tables = $this->db_tools->sql_list_tables();
						asort($tables);
						foreach ($tables as $table_name)
						{
							if (strlen($table_prefix) === 0 || stripos($table_name, $table_prefix) === 0)
							{
								$template->assign_block_vars('tables', array(
									'TABLE'	=> $table_name
								));
							}
						}
						unset($tables);

						$template->assign_vars(array(
							'U_ACTION'	=> $this->u_action . '&amp;action=download'
						));

						$available_methods = array('gzip' => 'zlib', 'bzip2' => 'bz2');

						foreach ($available_methods as $type => $module)
						{
							if (!@extension_loaded($module))
							{
								continue;
							}

							$template->assign_block_vars('methods', array(
								'TYPE'	=> $type
							));
						}

						$template->assign_block_vars('methods', array(
							'TYPE'	=> 'text'
						));
					break;
				}
			break;

			case 'restore':

				$this->page_title = 'ACP_RESTORE';

				switch ($action)
				{
					case 'submit':
						$delete = $request->variable('delete', '');
						$file = $request->variable('file', '');
						$download = $request->variable('download', '');

						if (!preg_match('#^backup_\d{10,}_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
						{
							trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
						}

						$backup_info = $this->get_backup_file($phpbb_root_path . 'store/', $file);

						$file_name = $matches[0];

						if (empty($backup_info) || !is_readable($backup_info['file_name']) || !$storage->exists($file_name))
						{
							trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
						}

						if ($delete)
						{
							if (confirm_box(true))
							{
								unlink($backup_info['file_name']);
								$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_DELETE');
								trigger_error($user->lang['BACKUP_DELETE'] . adm_back_link($this->u_action));
							}
							else
							{
								confirm_box(false, $user->lang['DELETE_SELECTED_BACKUP'], build_hidden_fields(array('delete' => $delete, 'file' => $file)));
							}
						}
						else if ($download || confirm_box(true))
						{

							if ($download)
							{
								$name = $matches[0];
								switch ($matches[1])
								{
									case 'sql':
										$mimetype = 'text/x-sql';
									break;
									case 'sql.bz2':
										$mimetype = 'application/x-bzip2';
									break;
									case 'sql.gz':
										$mimetype = 'application/x-gzip';
									break;
								}
								header('Cache-Control: private, no-cache');
								header("Content-Type: $mimetype; name=\"$name\"");
								header("Content-disposition: attachment; filename=$name");
								@set_time_limit(0);
								try
								{
									$fp = $storage->read_stream($file_name);
									while (!feof($fp))
									{
										echo fread($fp, 8192);
									}
									fclose($fp);
								}
								catch (\phpbb\storage\exception\exception $e)
								{
									// If open fails, just finish
								}
								flush();
								exit;
							}

							switch ($backup_info['extensions'])
							{
								case 'sql':
									$fp = fopen($backup_info['file_name'], 'rb');
									$read = 'fread';
									$seek = 'fseek';
									$eof = 'feof';
									$close = 'fclose';
									$fgetd = 'fgetd';
								break;

								case 'sql.bz2':
									$fp = bzopen($backup_info['file_name'], 'r');
									$read = 'bzread';
									$seek = '';
									$eof = 'feof';
									$close = 'bzclose';
									$fgetd = 'fgetd_seekless';
								break;

								case 'sql.gz':
									$fp = gzopen($backup_info['file_name'], 'rb');
									$read = 'gzread';
									$seek = 'gzseek';
									$eof = 'gzeof';
									$close = 'gzclose';
									$fgetd = 'fgetd';
								break;

								default:
									trigger_error($user->lang['BACKUP_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
									return;
							}

							switch ($db->get_sql_layer())
							{
								case 'mysql':
								case 'mysql4':
								case 'mysqli':
								case 'sqlite3':
									while (($sql = $fgetd($fp, ";\n", $read, $seek, $eof)) !== false)
									{
										$db->sql_query($sql);
									}
								break;

								case 'postgres':
									$delim = ";\n";
									while (($sql = $fgetd($fp, $delim, $read, $seek, $eof)) !== false)
									{
										$query = trim($sql);

										if (substr($query, 0, 13) == 'CREATE DOMAIN')
										{
											list(, , $domain) = explode(' ', $query);
											$sql = "SELECT domain_name
												FROM information_schema.domains
												WHERE domain_name = '$domain';";
											$result = $db->sql_query($sql);
											if (!$db->sql_fetchrow($result))
											{
												$db->sql_query($query);
											}
											$db->sql_freeresult($result);
										}
										else
										{
											$db->sql_query($query);
										}

										if (substr($query, 0, 4) == 'COPY')
										{
											while (($sub = $fgetd($fp, "\n", $read, $seek, $eof)) !== '\.')
											{
												if ($sub === false)
												{
													trigger_error($user->lang['RESTORE_FAILURE'] . adm_back_link($this->u_action), E_USER_WARNING);
												}
												pg_put_line($db->get_db_connect_id(), $sub . "\n");
											}
											pg_put_line($db->get_db_connect_id(), "\\.\n");
											pg_end_copy($db->get_db_connect_id());
										}
									}
								break;

								case 'oracle':
									while (($sql = $fgetd($fp, "/\n", $read, $seek, $eof)) !== false)
									{
										$db->sql_query($sql);
									}
								break;

								case 'mssql_odbc':
								case 'mssqlnative':
									while (($sql = $fgetd($fp, "GO\n", $read, $seek, $eof)) !== false)
									{
										$db->sql_query($sql);
									}
								break;
							}

							$close($fp);

							// Purge the cache due to updated data
							$cache->purge();

							$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_DB_RESTORE');
							trigger_error($user->lang['RESTORE_SUCCESS'] . adm_back_link($this->u_action));
							break;
						}
						else
						{
							confirm_box(false, $user->lang['RESTORE_SELECTED_BACKUP'], build_hidden_fields(array('file' => $file)));
						}

					default:
						$backup_files = $this->get_file_list($phpbb_root_path . 'store/');

						if (!empty($backup_files))
						{
							krsort($backup_files);

							foreach ($backup_files as $name => $file)
							{
								$template->assign_block_vars('files', array(
									'FILE'		=> sha1($file),
									'NAME'		=> $user->format_date($name, 'd-m-Y H:i', true),
									'SUPPORTED'	=> true,
								));
							}
						}

						$template->assign_vars(array(
							'U_ACTION'	=> $this->u_action . '&amp;action=submit'
						));
					break;
				}
			break;
		}
	}

	/**
	 * Get backup file from file hash
	 *
	 * @param string $directory Relative path to directory
	 * @param string $file_hash Hash of selected file
	 *
	 * @return array Backup file data or empty array if unable to find file
	 */
	protected function get_backup_file($directory, $file_hash)
	{
		$backup_data = [];

		$file_list = $this->get_file_list($directory);
		$supported_extensions = $this->get_supported_extensions();

		foreach ($file_list as $file)
		{
			preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches);
			if (sha1($file) === $file_hash && in_array($matches[2], $supported_extensions))
			{
				$backup_data = [
					'file_name' => $directory . $file,
					'extension' => $matches[2],
				];
				break;
			}
		}

		return $backup_data;
	}

	/**
	 * Get backup file list for directory
	 *
	 * @param string $directory Relative path to backup directory
	 *
	 * @return array List of backup files in specified directory
	 */
	protected function get_file_list($directory)
	{
		$supported_extensions = $this->get_supported_extensions();

		$dh = @opendir($directory);

		$backup_files = [];

		if ($dh)
		{
			while (($file = readdir($dh)) !== false)
			{
				if (preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
				{
					if (in_array($matches[2], $supported_extensions))
					{
						$backup_files[(int) $matches[1]] = $file;
					}
				}
			}
			closedir($dh);
		}

		return $backup_files;
	}

	/**
	 * Get supported extensions for backup
	 *
	 * @return array List of supported extensions
	 */
	protected function get_supported_extensions()
	{
		$extensions = ['sql'];
		$available_methods = ['sql.gz' => 'zlib', 'sql.bz2' => 'bz2'];

		foreach ($available_methods as $type => $module)
		{
			if (!@extension_loaded($module))
			{
				continue;
			}
			$extensions[] = $type;
		}

		return $extensions;
	}
}

// get how much space we allow for a chunk of data, very similar to phpMyAdmin's way of doing things ;-) (hey, we only do this for MySQL anyway :P)
function get_usable_memory()
{
	$val = trim(@ini_get('memory_limit'));

	if (preg_match('/(\\d+)([mkg]?)/i', $val, $regs))
	{
		$memory_limit = (int) $regs[1];
		switch ($regs[2])
		{

			case 'k':
			case 'K':
				$memory_limit *= 1024;
			break;

			case 'm':
			case 'M':
				$memory_limit *= 1048576;
			break;

			case 'g':
			case 'G':
				$memory_limit *= 1073741824;
			break;
		}

		// how much memory PHP requires at the start of export (it is really a little less)
		if ($memory_limit > 6100000)
		{
			$memory_limit -= 6100000;
		}

		// allow us to consume half of the total memory available
		$memory_limit /= 2;
	}
	else
	{
		// set the buffer to 1M if we have no clue how much memory PHP will give us :P
		$memory_limit = 1048576;
	}

	return $memory_limit;
}

function sanitize_data_mssql($text)
{
	$data = preg_split('/[\n\t\r\b\f]/', $text);
	preg_match_all('/[\n\t\r\b\f]/', $text, $matches);

	$val = array();

	foreach ($data as $value)
	{
		if (strlen($value))
		{
			$val[] = "'" . $value . "'";
		}
		if (count($matches[0]))
		{
			$val[] = 'char(' . ord(array_shift($matches[0])) . ')';
		}
	}

	return implode('+', $val);
}

function sanitize_data_oracle($text)
{
//	$data = preg_split('/[\0\n\t\r\b\f\'"\/\\\]/', $text);
//	preg_match_all('/[\0\n\t\r\b\f\'"\/\\\]/', $text, $matches);
	$data = preg_split('/[\0\b\f\'\/]/', $text);
	preg_match_all('/[\0\r\b\f\'\/]/', $text, $matches);

	$val = array();

	foreach ($data as $value)
	{
		if (strlen($value))
		{
			$val[] = "'" . $value . "'";
		}
		if (count($matches[0]))
		{
			$val[] = 'chr(' . ord(array_shift($matches[0])) . ')';
		}
	}

	return implode('||', $val);
}

function sanitize_data_generic($text)
{
	$data = preg_split('/[\n\t\r\b\f]/', $text);
	preg_match_all('/[\n\t\r\b\f]/', $text, $matches);

	$val = array();

	foreach ($data as $value)
	{
		if (strlen($value))
		{
			$val[] = "'" . $value . "'";
		}
		if (count($matches[0]))
		{
			$val[] = "'" . array_shift($matches[0]) . "'";
		}
	}

	return implode('||', $val);
}

// modified from PHP.net
function fgetd(&$fp, $delim, $read, $seek, $eof, $buffer = 8192)
{
	$record = '';
	$delim_len = strlen($delim);

	while (!$eof($fp))
	{
		$pos = strpos($record, $delim);
		if ($pos === false)
		{
			$record .= $read($fp, $buffer);
			if ($eof($fp) && ($pos = strpos($record, $delim)) !== false)
			{
				$seek($fp, $pos + $delim_len - strlen($record), SEEK_CUR);
				return substr($record, 0, $pos);
			}
		}
		else
		{
			$seek($fp, $pos + $delim_len - strlen($record), SEEK_CUR);
			return substr($record, 0, $pos);
		}
	}

	return false;
}

function fgetd_seekless(&$fp, $delim, $read, $seek, $eof, $buffer = 8192)
{
	static $array = array();
	static $record = '';

	if (!count($array))
	{
		while (!$eof($fp))
		{
			if (strpos($record, $delim) !== false)
			{
				$array = explode($delim, $record);
				$record = array_pop($array);
				break;
			}
			else
			{
				$record .= $read($fp, $buffer);
			}
		}
		if ($eof($fp) && strpos($record, $delim) !== false)
		{
			$array = explode($delim, $record);
			$record = array_pop($array);
		}
	}

	if (count($array))
	{
		return array_shift($array);
	}

	return false;
}

invenio
Registered User
Posts: 94
Joined: Wed Dec 09, 2015 1:45 pm
Contact:

Re: The selected file to backup is invalid.

Post by invenio » Mon Jul 08, 2019 6:57 pm

It's on line 219 on the default v3.2.7 file, but the text you have in your post is not the same file.

Make sure you have the correct version of phpbb, and then just follow the directions that people have posted here like 5 times in a row in different ways.

Post Reply

Return to β€œ[3.2.x] Support Forum”