<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — BACKUP FILE]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=5598&amp;type=atom" />
	<updated>2015-03-12T01:05:25Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=5598</id>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22869#p22869" />
			<content type="html"><![CDATA[<p>Hi TM,</p><p>I agree with you too.&nbsp; Database backup file should not be tempered and to prevent that, prevent download and view is one of the ways I could do for now.</p><p>Hi APMuthu,</p><p>The codes work fine.&nbsp; &nbsp;Thank you so much.</p>]]></content>
			<author>
				<name><![CDATA[khkoh]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18597</uri>
			</author>
			<updated>2015-03-12T01:05:25Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22869#p22869</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22838#p22838" />
			<content type="html"><![CDATA[<p>@tm: You are right about restriction of backups to responsible and authorised users only. The solution I provided would be useful if some critical tables are just read only views made from tables outside of FA.</p><p>@khkoh: Anyone who takes a restricted backup using the script here can always inject the necessary sqls with different users, security_roles, etc., and upload and restore them. It can also be able to exclude certain prefixed tables that may not be part of native FA at all and managed elsewhere. If prefixes are used, non prefixed tables get excluded in the original code itself.</p><p>In preparing this code hack, understanding and documenting the backup process has been achieved.</p><p>Restoring from a completely new hacked backup file with only insert statements can be a nice way of importing records into FA and in some instances provide a base for a new CoA!</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-03-10T06:40:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22838#p22838</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22837#p22837" />
			<content type="html"><![CDATA[<p>Restoring a backup inserts data into the database. It&#039;s not a major security issue. It&#039;s how things work.</p><p>I guess you could prevent your users from uploading/downloading backups, but that won&#039;t stop them from overwriting each other’s data. That&#039;s why you don&#039;t want to give users access to the backups on a multi-user system in the first place.</p>]]></content>
			<author>
				<name><![CDATA[tm]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17873</uri>
			</author>
			<updated>2015-03-10T04:48:23Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22837#p22837</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22834#p22834" />
			<content type="html"><![CDATA[<p>Dear APMuthu,</p><p>I will be testing the scripts and I will let you know how it goes...&nbsp; Many thanks.</p><p>Dear TM,</p><p>Thanks for responding to this post.</p><p>I noted a major security issue if we have the tables 0_users, 0_security_roles etc included in the backup sql files. The 0_users encrypted password can be replaced (by users who is familiar with the encryption) and the roles can be changed. If the data base is then restored, the admin/users&#039; passwords can be compromised.&nbsp; I have tested it and I found that this is a real vulnerability. </p><p>To the minimum, I feel that there should be 2 types of backups provided.&nbsp; 1. &quot;Full back up&quot; including all the tables and only to be done by the authorized personnel such as system administrator or the head of the company.&nbsp; Ordinary users should not be allowed to perform this backup.&nbsp; 2.&nbsp; &quot;User data backup&quot; for &quot;undo&quot; purpose and this should exclude the tables that contain the login, passwords and access control.</p>]]></content>
			<author>
				<name><![CDATA[khkoh]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18597</uri>
			</author>
			<updated>2015-03-10T02:53:01Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22834#p22834</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22833#p22833" />
			<content type="html"><![CDATA[<p>What you are describing is not a backup. It is, at best, an &quot;undo&quot; feature for your users. And a dangerous one, if you have more than one user.</p><p>There is no way to restore the data on a fresh system using these &quot;backups&quot; because, just like incremental backups, they require a &quot;base&quot; backup to start from.</p><p>Whatever it is you are trying to achieve, this is not the way to do it.</p>]]></content>
			<author>
				<name><![CDATA[tm]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17873</uri>
			</author>
			<updated>2015-03-09T16:40:49Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22833#p22833</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22832#p22832" />
			<content type="html"><![CDATA[<p>My previous solutions do not work because the $all_tables is an array of arrays.</p><p>Lines 505 to 513 in <strong>admin/db/maintenance_db.inc</strong>:<br /></p><div class="codebox"><pre><code>    // get auto_increment values and names of all tables
    $res = db_query(&quot;show table status&quot;);
    $all_tables = array();
    while($row = db_fetch($res))
    {
        if (($conn[&quot;tbpref&quot;] == &quot;&quot; &amp;&amp; !preg_match(&#039;/[0-9]+_/&#039;, $row[&#039;Name&#039;])) ||
            ($conn[&quot;tbpref&quot;] != &quot;&quot; &amp;&amp; strpos($row[&#039;Name&#039;], $conn[&quot;tbpref&quot;]) === 0))
            $all_tables[] = $row;
    }</code></pre></div><p>is now replaced with:<br /></p><div class="codebox"><pre><code>    // get auto_increment values and names of all tables
    $res = db_query(&quot;show table status&quot;);
    $all_tables = array();
    $skip_tables_list = Array(&#039;users&#039;, &#039;security_roles&#039;, &#039;sql_trail&#039;);
    for ($i = 0; $i &lt; count($skip_tables_list); $i++) {
        $skip_tables_list[$i] = $conn[&quot;tbpref&quot;].$skip_tables_list[$i];
    }
    while($row = db_fetch($res))
    {
        if (($conn[&quot;tbpref&quot;] == &quot;&quot; &amp;&amp; !preg_match(&#039;/[0-9]+_/&#039;, $row[&#039;Name&#039;])) ||
            ($conn[&quot;tbpref&quot;] != &quot;&quot; &amp;&amp; strpos($row[&#039;Name&#039;], $conn[&quot;tbpref&quot;]) === 0))
            if (!(in_array($row[&#039;Name&#039;], $skip_tables_list, true)))
                $all_tables[] = $row;
    }</code></pre></div><p>The variable <strong>$skip_tables_list</strong> is populated with the names of tables to be skipped (without table prefixes).</p><p>The tables missing tables in the backup remain untouched in the database when restored.</p><p>The <a href="https://frontaccounting.com/fawiki/index.php?n=Help.BackupAndRestoreDatabase">wiki</a> has been updated and the code has been tested.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-03-09T16:15:27Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22832#p22832</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22820#p22820" />
			<content type="html"><![CDATA[<p>Dear APMuthu,</p><p>Thanks very much for the codes and Wiki&#039;ed it.</p><p>I have added the codes provided and test run it, the few excluded tables still exist in the backup .sql file (please see the appended codes).&nbsp; I inspected the few variables and arrays and I couldn&#039;t spot the issue.&nbsp; I need your advise on this....</p><p>Another potential issue which is related to the restoration of this modified backup file.&nbsp; As stated in the Wiki, the restore functions will first drop all the tables before being recreated and populated. </p><p>Wiki: &quot;On restoration, these tables will first be dropped before being recreated and populated.&quot;</p><p>If the tables are excluded, unless the backup .sql totally ignore these excluded tables and they are not dropped during restoration.&nbsp; (I hope this is the case).&nbsp; Otherwise the Restoration of these excluded tables will be &quot;emptied&quot; and it will make the FA not functioning as the data are missing (for example, the users will not be able to login since the user table is empty).&nbsp; &nbsp;</p><p>I&#039;m sorry I could not contribute to the coding but I could only share my thoughts with regards to this issue.&nbsp; Your help is very much appreciated.</p><p>Thank you!</p><p>KH</p><p>=====================<br />&nbsp; &nbsp;$res = db_query(&quot;show table status&quot;);<br />&nbsp; &nbsp; $all_tables = array();<br />&nbsp; &nbsp; while($row = db_fetch($res))<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; if (($conn[&quot;tbpref&quot;] == &quot;&quot; &amp;&amp; !preg_match(&#039;/[0-9]+_/&#039;, $row[&#039;Name&#039;])) ||<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ($conn[&quot;tbpref&quot;] != &quot;&quot; &amp;&amp; strpos($row[&#039;Name&#039;], $conn[&quot;tbpref&quot;]) === 0))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $all_tables[] = $row;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; <br />//Skip tables during backup:&nbsp; The codes below skipped the few tables that may cause security issues such as &#039;0_users&#039;, &#039;seicurity_roles&#039; etc.</p><p>$skip_tables_list = Array(&#039;users&#039;, &#039;security_roles&#039;, &#039;sql_trail&#039;);</p><p>&nbsp; &nbsp; foreach ($skip_tables_list as $skip_table_name) {<br />&nbsp; &nbsp; &nbsp; &nbsp; if (($key = array_search($conn[&quot;tbpref&quot;].$skip_table_name, $all_tables)) !== false) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; unset($all_tables[$key]);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />// End Skip Files during backup&nbsp; &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; // get table structures<br />&nbsp; &nbsp; foreach ($all_tables as $table)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; $res1 = db_query(&quot;SHOW CREATE TABLE `&quot; . $table[&#039;Name&#039;] . &quot;`&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; $tmp = db_fetch($res1);<br />&nbsp; &nbsp; &nbsp; &nbsp; $table_sql[$table[&#039;Name&#039;]] = $tmp[&quot;Create Table&quot;];<br />&nbsp; &nbsp; }<br />===========================</p>]]></content>
			<author>
				<name><![CDATA[khkoh]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18597</uri>
			</author>
			<updated>2015-03-09T03:23:52Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22820#p22820</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22814#p22814" />
			<content type="html"><![CDATA[<p>A more generic version of the insert code above is:<br /></p><div class="codebox"><pre><code>$skip_tables_list = Array(&#039;users&#039;, &#039;security_roles&#039;, &#039;sql_trail&#039;);

foreach ($skip_tables_list as $skip_table_name) {
    if (($key = array_search($conn[&quot;tbpref&quot;].$skip_table_name, $all_tables)) !== false) {
        unset($all_tables[$key]);
    }
}</code></pre></div><p>This information has now been <a href="https://frontaccounting.com/fawiki/index.php?n=Help.BackupAndRestoreDatabase">wiki</a>-ed.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-03-08T07:02:01Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22814#p22814</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22798#p22798" />
			<content type="html"><![CDATA[<p>Lines 506 to 513 of <strong>admin/db/maintenance_db.inc</strong>:<br /></p><div class="codebox"><pre><code>    $res = db_query(&quot;show table status&quot;);
    $all_tables = array();
    while($row = db_fetch($res))
    {
        if (($conn[&quot;tbpref&quot;] == &quot;&quot; &amp;&amp; !preg_match(&#039;/[0-9]+_/&#039;, $row[&#039;Name&#039;])) ||
            ($conn[&quot;tbpref&quot;] != &quot;&quot; &amp;&amp; strpos($row[&#039;Name&#039;], $conn[&quot;tbpref&quot;]) === 0))
            $all_tables[] = $row;
    }</code></pre></div><p>gets the list of tables to be exported into the array variable <strong>$all_tables</strong>. Now all you need to do is to remove the table names you do not want from them.</p><p>To do so, after the above code insert the following:<br /></p><div class="codebox"><pre><code>if (($key = array_search($conn[&quot;tbpref&quot;].&#039;users&#039;, $all_tables)) !== false) {
    unset($all_tables[$key]);
}
if (($key = array_search($conn[&quot;tbpref&quot;].&#039;security_roles&#039;, $all_tables)) !== false) {
    unset($all_tables[$key]);
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-03-07T12:50:38Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22798#p22798</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[BACKUP FILE]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22788#p22788" />
			<content type="html"><![CDATA[<p>Hi there,</p><p>I would like to exclude a few tables such as &#039;0_users&#039; or `0_security_roles` when running the backup.&nbsp; I attempt to make changes to admin/db/maintenance_db.inc to exclude these tables, but due to my limited knowledge in php, I was unable to put this function &quot;--ignore-table&quot; at the right place.</p><p>Could someone provide some guidance?</p><p>Thanks.</p><p>KH</p>]]></content>
			<author>
				<name><![CDATA[khkoh]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18597</uri>
			</author>
			<updated>2015-03-06T11:09:34Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22788#p22788</id>
		</entry>
</feed>
