Ignore Mysql Tables using regex when using Mysqldump command

Hi guys,

We can ignore database tables while taking mysqldump using the below command

mysqldump -u username -p database –ignore-table=database.table1 –ignore-table=database.table2 > database.sql

However if we want to ignore more tables we need to add the tables manually and its a real pain in the A$$

Here I am showing how to take the mysqldump using regex to ignore mysql tables.

For example:- If I want to ignore the below tables starting from

1) alice_token,

2) import_

3)sales_order_item_shipment_tracking

4)sales_order_item_status_history

5)stock_import

6)ums

root@vishnu-machine# cd /var/lib/mysql/<database>

root@vishnu-machine:/var/lib/mysql/<database># echo ‘[mysqldump]’ > mydump.cnf

root@vishnu-machine:/var/lib/mysql/<database>#  mysql -NBe “select concat(‘ignore-table=’, table_schema, ‘.’, table_name) from information_schema.tables where table_name REGEXP ‘^(alice_token|import_|sales_order_item_shipment_tracking|sales_order_item_status_history|stock_import|ums)’;” > mydump.cnf

And verify the file “mydump.cnf”

root@vishnu-machine:/var/lib/mysql/<database># cat mydump.cnf

ignore-table=<database>.alice_token

ignore-table=<database>.import_token

ignore-table=<database>.import_sales

ignore-table=<database>.sales_order_item_shipment_tracking

ignore-table=<database>.sales_order_item_status_history

ignore-table=<database>.stock_import

ignore-table=<database>.ums

You can see the above entries in the file “mydump.cnf”

root@vishnu-machine:/var/lib/mysql/<database># mysqldump –defaults-file=mydump.cnf -u root -p <database> > vishnu.sql

And here it is new dump without tables as mentioned above.

 

Advertisements

PhantomJS and Load Speed test for websites

PhantomJS is an optimal solution for

1) Headless Website Testing

2) Screen Capture

3) Page Automation

4) Network Monitoring

Please check this link  http://phantomjs.org/

TO INSTALL PHANTOMJS

cd /usr/local/share
wget https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2
tar xjvf phantomjs-1.9.1-linux-x86_64.tar.bz2
ln -s /usr/local/share/phantomjs-1.9.1-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
ln -s /usr/local/share/phantomjs-1.9.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
ln -s /usr/local/share/phantomjs-1.9.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
# Additional package
apt-get install fontconfig

Then go to the location

root@machine# cd /usr/local/share/phantomjs-1.9.1-linux-x86_64/examples

root@machine# vim loadspeed.js

ADD OUR EDITED FILE TO GET THE LOAD PAGE SPEED

var args = require(‘system’).args;
    if(args[1] === undefined){
        console.log(‘you should provide an url’);
        phantom.exit();
    }

var namshiUrl = args[1];

var page = require(‘webpage’).create(),
    system = require(‘system’),
    t,address;

if (system.args.length === 1) {
    console.log(‘Usage: loadspeed.js ‘+ namshiUrl);
    phantom.exit(1);
} else {
    t = Date.now();
    address = system.args[1];
    page.open(address, function (status) {
      if (status !== ‘success’) {
            console.log(‘FAIL to load the address’);
        } else {
            t = Date.now() – t;
            console.log(‘Page title is ‘ + page.evaluate(function () {
                return document.title;
            }));
            console.log(‘Loading time ‘ + t + ‘ msec’);
        }
        phantom.exit();
    });
}

THEN TEST IT

root@vishnu-machine:~# for weburl in http://google.com http://yahoo.com ; do phantomjs /usr/local/share/phantomjs-1.9.1-linux-x86_64/examples/loadspeed.js ${weburl}; done

THEN INORDER TO DOING THIS WRITE A SCRIPT

#!/bin/bash
true=0
for weburl in http://google.com http://yahoo.com http://hotmail.com ; do /usr/local/bin/phantomjs /usr/local/share/phantomjs-1.9.1-linux-x86_64/examples/loadspeed.js ${weburl}; done  > abc.txt
cat abc.txt | awk ‘{print $3}’ | sed -n “2~2 p” > abc2.txt
for i in `cat abc2.txt`
do
if [ $i -gt 12000 ]
then
    true=1
fi
done
if [ $true -eq 1 ]
then
   mail -s loadtime mailadddress@domain.com < abc.txt
fi