Page 1 of 1
SBMD - Simple Backup MySQL Database - Skip the tables part
Posted: 03 Mar 2016, 19:06
by sannisinas
Hi,
I am looking in to your
SBMD - Simple Backup MySQL Database php module. Very nice work. Just wondering, and sorry for asking but I am a beginner, is it difficult to remove the tables part? I always want a full backup.
Thanks a lot
SBMD - Simple Backup MySQL Database - Skip the tables part
Posted: 04 Mar 2016, 09:16
by Admin
Hi,
I don't understand exactly what you mean with "removing the tables part".
You can make a full backup of the database by selecting all the tables.
If you want all the tables to be directly selected, replace this code in the bkmysql.php file (lines 272-280):
Code: Select all
if(ch_all){
var ch_btn = ch_all.querySelector('input');
var tables = document.querySelectorAll('#frm_cht .ch_tables input');
ch_all.addEventListener('click', function(){
if(tables){
for(var i=0; i<tables.length; i++) tables[i].checked = ch_btn.checked;
}
});
}
With this code:
Code: Select all
if(ch_all){
var ch_btn = ch_all.querySelector('input');
var tables = document.querySelectorAll('#frm_cht .ch_tables input');
ch_btn.checked = true;
function selBkTables(){
for(var i=0; i<tables.length; i++){
tables[i].checked = ch_btn.checked;
tables[i].parentNode.style.display ='none';
}
}
ch_all.addEventListener('click', selBkTables);
selBkTables();
}
- With this change, all the tables will be automatically selected, and the list with their names will be hidden. Then, just click the Backup button.
- if you want something else, please explain more exactly.
Do you want to use the bkmysql.php page, or to use the backupmysql class methods in another php file?
SBMD - Simple Backup MySQL Database - Skip the tables part
Posted: 04 Mar 2016, 09:22
by sannisinas
This is exactly what I needed yes
thanks I will do some testing. I indeed want to use it in another php file. Well in a magento module. Nice challenge to learn both php and magento
SBMD - Simple Backup MySQL Database - Skip the tables part
Posted: 04 Mar 2016, 10:40
by Admin
You can use this code into a php file to create backup of all the tables in mysql database, with the backupmysql class:
Code: Select all
<?php
$lang ='en'; //indice of the "lang_...json" file with texts
$dir ='backup/'; //folder to store the ZIP archive with SQL backup
//data for connecting to MySQL
$conn_data = ['host'=>'localhost', 'user'=>'user_name', 'pass'=>'password', 'dbname'=>'database_name'];
//set object of backupmysql class
include 'backupmysql.class.php';
$bk = new backupmysql($lang, $dir);
$bk->setMysql($conn_data); //set connection
$tables = $bk->getTables(); //array with all the tables in database
//if no error
if($bk->error === false){
//if tables, creates the SQL backup of all the tables and saves it in ZIP archive (get succesful or error message)
$bk_sql = (count($tables) >0) ? $bk->saveBkZip($tables) :'No tables in database';
echo $bk_sql;
}
else echo $bk->error;
SBMD - Simple Backup MySQL Database - Skip the tables part
Posted: 05 Mar 2016, 06:48
by sannisinas
Thanks a lot, I will do some checking. Most likely a lot of new questions will come up. I basically want to use to use it to backup the database, filesystem and then move it and make a test system with the files gathered. So I also need to input some variables of the destination database. Fun stuff to work on