mysqldump by example

MySQL Dump is probably one of the best tool to take copies of databases, and it comes with MySQL, so you don’t need to install more stuff.

Example 1: Backup all databases (Use with caution, see below)
IMPORTANT: if you dump this to another server, you will lose all users on the target server, this is because the database named mysql (not the database engine but the actual database that has the users) on the target server is overwritten by the one from the source

Added note: If you want to monitor how large the uncompressed dump file has gone, or in other words, how much data mysqldump has brought so far, you can use PV, in this example, i expect the data to be 123GBs so i put that in so that PV can tell me what percentage of that i have finished, it will tell me the exact number of bytes anyways, but this is visually easier.

mysqldump --opt -u root --password="yourpass" databasename | pv -s 123g | pigz -c > dumpfile.sql.gz

 

1- Dump all databases

mysqldump -u root --password="thispassword" --all-databases > thisdatabasedump.sql

2- Dump all databases and gzip compress the output file, gzcompress is like compression used in zip files, this command compresses on the fly (make sure gzip is installed)

mysqldump --opt -u root --password="thispassword" --all-databases | gzip -9 > thisdatabasedump.sql.gz

3- Dump all databases and BZIP compress the output file, BZIP compression is better than gzip compression, but takes significantly more time, like the one before this command compresses on the fly (make sure you have bzip2 installed)

mysqldump --opt -u root --password="thispassword" --all-databases | bzip2 > thisdatabasedump.sql.bz2

4- If you have a server with multiple processors, you can overcome the slowness of bzip2 by simply making all the CPUs (real or virtual or hyper threaded) work on compressing at the same time, the application is called parallel bzip2 (make sure pbzip2 is installed)

mysqldump --opt -u root --password="thispassword" --all-databases | pbzip2 > thisdatabasedump.sql.bz2

4.5- If your server has 8CPUs and you only want 7 of them to do zipping so that one of them can be dedicated to mysqldump

mysqldump --opt -u root --password="thispassword" --all-databases | pbzip2 -p7 > thisdatabasedump.sql.bz2

I will not give any more examples about compression, obviously, as you can see from the examples above, to compress on the fly all you need to do is replace the section ( > thisdumpfile.sql ) with ( | pbzip2 > thisdumpfile.sql.bz2 )

5- Dump a certain database to the file

mysqldump --opt -u root --password="thispassword" thisparticulardbsname > thisdumpfile.sql

6- Dump certain databaseS

mysqldump --opt -u root --password="thispassword" --databases db1name db2name db3name db4name > thisdumpfile.sql

7- Dump certain tables from within a database

mysqldump --opt -u root --password="thispassword" databasename table1name table2name table3name > thisdumpfile.sql

8- Exclude certain tables from the mysqldump

 mysqldump --opt -u username --password="thispassword" databasename --ignore-table=databasename.table1 --ignore-table=databasename.table2 > database.sql

Disable Windows has detected a hard disk problem message in windows

The following are the steps to disable the error message associated with a bad hard drive, the message that windows will display after every login, we will disable it from within windows without disabling it in the BIOS.
error

The message above reads (On my computer, on yours, the disk model number and the names of the volumes will probably be different.

Windows has detected a hard disk problem.
Back up your files immediately to prevent information loss, and then contact the computer manufacturer to determine if you need to repair or replace the disk

Then, you are presented with the following two options

Start the backup process

Ask me again later
-- If the disk fails before the next warning, you could lose all of the programs and documents on the disk.

In the show details dialogue you should see 

Immediate steps
Because disk failure will cause you to loose all programs, files and documents on the disk, you should back up your important information immediately, try not to use your computer until you have repaired or replaced the hard disk.
Which disk is failing
The following hard disks are reporting failure.
Disk name: TOSHIBA MK3264GSXN ATA Device
Volume: C:, D:, E: 

My advice would be

Do not disable S.M.A.R.T. from BIOS, rather, ask windows not to display this message, this is because for a failing disk, you would want the S.M.A.R.T. data accessible from other programs or to keep an eye on it.

To disable this error message from within windows, do the following

click the start button and enter the word “task” in the search box, Task Scheduler should appear, right click it and chose run as administrator.
Once it is open, follow the tree to your left as follows
“Task Scheduler Library” => “Microsoft” => “Windows”. => “DiskDiagnostic”

As shown in the image, select the second entry, right click it, then click disable.

The following is the dialogue
diskdiag

close, and restart your computer to check if it worked.

The Linux DD command

To detect the progress or how far dd has come in a running copy, open a second terminal window, run top to get the id of the dd process, then issue the command kill -USR1 xxxx (replace xxx with the actual ID of the process), now it may appear that nothing happened, but swicth the terminal to the one dd is running in

you should see something like

1036902161+0 records in
1036902160+0 records out
530893905920 bytes (531 GB) copied, 29702.1 s, 17.9 MB/s

Recovering deleted files from ext4 partition

Update, although extundelete restrored most of my files, some files could only be restored with no file name through an application that is installed with testdisk called photorec

So, what happened was that i added a directory to eclipse, a message appears, i hit enter accidentally, all the files in the web directory are lost, no backup, years of programming…

Instantly, i shut down the computer so that i do not overwrite the disk space with new files and logs and the like, i got a larger disk (1.5tb) and did the DD first (i recommend gddrescue in place of DD just in case your disk has bad sectors).

Installed Linux (Debian 7) on the new disk, installed the hard drive from the other computer to the new PC, then installed the software i always use to recover files, testdisk, test disk did not work as expected, on both disks, when it comes to the ext4 partition, the process that ended in an error would be as follows

testdisk
create log file
Chose the 1TB disk (the one with the deleted files
Partition type (INTEL)
Advanced
Chose the main partition *(ext4) and chose List (left and right arrow keys)
Damn, the error.

TestDisk 6.13, Data Recovery Utility, November 2011
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org
 1 * Linux                    0  32 33 119515  60 33 1920010240
Can't open filesystem. Filesystem seems damaged.

So, i quit TestDisk and installed
apt-get install extundelete

extundelete /dev/sdb1 --restore-directory /var/www

This way, i only restore the files from that direcotry, if you want all the deleted files, you could surely use something like

extundelete /dev/sda4 --restore-all

Anyway, my files are back, a few are missing, but i am sure i can deal with that

MySQL – Can’t change ownership of the file Errcode: 1

When trying to repair tables (or optimise), there seems to be an error that is giving me a hard time.

The SQL statement REPAIR TABLE mytablename; returns the following

+---------------------+--------+----------+----------------------------------------------------------------------------------------------+
| Table               | Op     | Msg_type | Msg_text                                                                                     |
+---------------------+--------+----------+----------------------------------------------------------------------------------------------+
| mydbase.mytablename | repair | error    | 1 when fixing table                                                                          |
| mydbase.mytablename | repair | Error    | Can't change ownership of the file '/hds/wd1tb_2/mysql/mydbase/mytablename.MYD' (Errcode: 1) |
| mydbase.mytablename | repair | status   | Operation failed                                                                             |
+---------------------+--------+----------+----------------------------------------------------------------------------------------------+

So, the only solution up to now is to

chmod -R 700 /hds/wd1tb_2/mysql/
chown -R mysql:mysql /hds/wd1tb_2/mysql/

This error has already been reported as a big long time ago, but it seems to be still there, this is the only way around the situation, and it does not seem to have been resolved with MySQL 5.5.33-0+wheezy1

Extracting 7z files

On debian, i always recommend you install p7zip-full not p7zip

To extract with 7zip on linux, in order to maintain directory structure, use the x rather than the e, so the command to extract is

7za x file.7z

The file above would have been produced by a command such as

7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on archive.7z dir1

The above line adds all files from directory “dir1” to archive archive.7z using “ultra settings”

Quickly disable and enable autoplay and autorun

Disable auto run and auto play.

1- Download : the first to disables windows auto play (to protect your computer), the other enables it if you ever change your mind.
You will want to save the files not to view them, so in firefox you would right click then “save link as”, similar functions are available in other browsers.
Download Disable Auto Play
Download Enable Auto Play

2- Run the file you downloaded
3- Restart your computer

Why diable autorun / autoplay ?

i disable it because i don’t like auto run viruses that my antivirus don’t catches ! maybe you have your reasons, like you don’t like the thing that pops up when you insert a flash stick or a DVD.

What is the difference between autorun and autoplay ?

AutoPlay is the new AutoRun (Windows vista and above)

Auto Run : the original from windows 95, the system executes the program mentioned in autorun.inf when removable media is inserted.

Auto Play : Like auto run, but when and if there is no autorun.inf file, the OS will try to guess and give you choices.

All you need to disable it, is to download the following from above, and run the one named disable-autoplay.reg, if you want to re-enable it for some reason, run the file that says enable-autoplay.reg

What happens when i run the files above ?

Rather than asking you to use regedit to edit your registry and change values or add them, we made a reg file with the values for you to download and use, what you are downloading is a text file (and not a program) that will instruct your computer on the new registry values.

The values that are modified (or added if the key does not exist) are

HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer ENTRY NoDriveTypeAutoRun
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionpoliciesExplorer ENTRY NoDriveTypeAutoRun

The disable file will set the values above to 000000FF (Decimal 255) to disable auto play (autorun), and the enable file above will set auto play (autorun) to 00000001 (Decimal 1).

Windows provides a tool to do it too, you can do this using gpedit.msc.
Hit start, type gpedit.msc then when that appears in the list, hit enter.
Computer Configuration >> Administrative Templates >> Windows Components >> AutoPlay Policies

That will open a new window that will allow you to enable or disable autorun.

Or you could just click one of the files above and run it on your computer.

My SSL price hunt, what’s on the market.

Edited on 2014-10-20. I use this post to keep track of where to get SSL certificates when i need them, thought i should share this stuff and save people some time looking for cheap SSL certificates

I also changed the title of this post from “workaround to no godaddy promo code works for ssl” to “My SSL price hunt, what’s on the market”. because godaddy and his resellers are no longer the no brainer choice, Hence i am looking for something else. I changed the title even before looking, but let’s see how it goes, i will also keep this page updated every time i look for SSL deals.

Irrelevant to most: Today i am not only looking for any SSL supported by many browsers, i am looking for a certificate that works with PolarSSL and openssl since communication is going to be done through lib cURL.

Note: If you buy the certificate for 1 year, you can use the promo code 3.88DEAL to get the ssl for $3.88, this coupon was valid on 3 December 2014.

I will look no further, i found SSL certificates as cheap as $4 at SSLs.com, i am not affiliated with them, i do not know who they are, and i am not making any money out of you buying this certificate, It is just honest advice. ssls.com is namecheap, their paypal payment address on the time of this post is (You sent a payment of $3.88 USD to UnifiedRegistrar (support@namecheap.com))

The older post from 2013 recommended using a godaddy reseller (http://store.polodomains.com/ssl/ssl-certificate.aspx?ci=8347&prog_id=easywebdns) since godaddy SSL coupons are no longer a good enough discount to go below 28.99, one year after, i am redoing the investigation.

Again, this is where i keep record of what is available on the market for proper SSL certificates, this is not an exhaustive study, If you know of anything cheaper, please let me know.

Reminders and state of affairs.

– Free – startssl provides free SSL certificates, but the certificate will have to bear my personal details (Emailing passport, and other identification ), when this is a company, I don’t want my name on it especially if this is a client, the idea is cool, but unfortunately, only suitable for personal use.

– $29 – Godaddy’s $69 certificate has coupons on the internet, best of which gives around 40% off, this makes the certificate cost around $41.4, still more expensive that the reseller ( http://store.polodomains.com/ssl/ssl-certificate.aspx?ci=8347&prog_id=easywebdns ) so godaddy certificates are still, when baught from a reseller priced at $29

– $4 – Commodo certificates can be bought from any reseller for $4 (try ssls, they are a reseller of this).
———————————–
Older post from 2013-11-4
———————————–
So it seems there are no working promo codes available for godaddy. i am not coming to this as a conclusion, i actually made an affiliate account and went in to take a look at the available promo codes. Nothing for SSL that can take you under $28.

the best deal i found was 32% off which is still not cheap

So, the solution for me was to get the SSL certificate from a godaddy reseller for $29. i got mine through this link… while godaddy puts up new promo codes for SSL

NOTE: THIS IS NOT AN AFFILIATE LINK, THIS IS A DIRECT LINK TO THE PAGE
http://store.polodomains.com/ssl/ssl-certificates.aspx?ci=1790&prog_id=easywebdns

Happy savings

Stopping backscatter from postfix bounce

This is a quick one because i know you have no time to look into how mail servers work in extreme detail, so here it is.
This is a fast resolution to your backscatter problem, yet, after this resolution, it might take the spammer some time to realize that your server is no longer including the original message in the responce.

postconf -e 'bounce_size_limit = 1'

What this does is that it makes your message bounce with the headers but not the body of the message, which makes the spammer who is targeting your server loose interest *(because she can not make use of the bounced message if the body is missing)

right after you need to

/etc/init.d/postfix reload
/etc/init.d/postfix restart

Your choice 🙂

And this is the fastest solution, this is because any other solution will require you to investigate the whole setup, while this solution is a simple solution that is still effective.

Configuring firefox display mixed content

Well, not long after chrome started blocking active content from non https locations when pages were in https, firefox is doing the same with the new version.

The answer is simple and very intuitive (found it in 10 seconds), and i am not sure why no one has blogged about it yet.

1- In the address bar, visit about:config (Yes, just type this in the firefox URL address bar)
2- in the search, look for the word active, you will see a few parameters with the word active
3- find the one that reads (security.mixed_content.block_active_content) and double click the word TRUE that is in front of it so that it becomes false.
4- Close the config page

Now firefox would not mind active content

Always keep in mind that firefox did not do this for nothing, and that there is a security issue with mixed active content, in an ideal world, website makers would resolve the issue, and would make wise judgment on when it is ok to stream mixed content, and when cookies should only work in SSL (Part of cookie functionality), but since we don’t live in that world, Firefox has decided to deal with it from the browser side.