Connect to a different database server within command line utility

In sqlcmd, you can connect to a different server by this command:

:connect MyServer

The above command will attempt to use integrated / Windows Active Directory authentication. To use traditional Sql Server authentication, use this instead:

:connect MyServer -U MyLogin

You can do the same kind of thing in Oracle Sql Plus by using this command:

conn[ect] MyLogin@OracleSID

For mysql command line, use this:

connect -h MyServer -u MyLogin -p

That is assuming that you are allowed to login to the MySql server from whereever you are now.

My WordPress backup and restore process

As I am writing and publishing more and more blog entries, it becomes important that I have good and reliable backups. I know that if something happens and I cannot recover my entries and comments, I would be terribly upset. So I want to share my process here. Please feel free to share your backup methods by commenting. Hopefully somebody will find it useful.

Backup comprises two parts:

1. File backup

On a Linux machine with Apache, the default web files and directories reside in /var/www/html. Yours may be different. This include all php files and sub-directories like wp-content, wp-include, etc.

The easiest way to do it is to use tar command with -z to compress them. My post here gives you a pointer on tar.

These files are fairly static, so you do not need to back them up too often. You want to do file backup after you tried a new theme, installed a new plugin, etc. You should transfer this backup to a different box, in case the web host dies.

2. Database backup

For mysql database backup, you can use mysqldump, a utility that comes with mysql. mysqldump will iterate through all tables within the database, get their ddl, and dump all data in the form of insert statements. Below is the code to dump everything out and compress them using gzip:

mysqldump -q -e -hlocalhost -uLogin -pPassword MyBlogDb | gzip – > ./BlogDbBackup.sql.gz

Once again, gzip can shrink the size down pretty substantially. So do use it, especially if you have space issues.

There is a database backup plugin that comes with WordPress 2, which is the method I use. However, you do need to run chmod 777 on your database backup directory. If not, you will see the warning message of not enough privilege on your WordPress manage page. And you should be able to find out the backup directory name from that page, so you can run chmod.

In addition to the backup plugin, I also installed the wp-cron plugin. With wp-cron, I can schedule daily database backup and send it to an email address I defined. If I have a choice, I’d rather put everything in a shell script that backs everything up, compress them, and email the file to me. I then use cron to schedule it. However, since I am not root on my web host, I have had troubles setting up a smtp client for email, as documented here.

Now backup is done. The next step is to make sure my backup files work. I set up a standalone LAMP (Linux, Apache, MySql, PHP) box, extracted php files, restored the database by running:

mysql -hlocalhost -uLogin -p MyBlogDb < BlogDbBackup.sql I then modified wp-config.php file. And behold, it worked. Even my Chinese entries displayed properly. In a future post, I will share with you some of the lessons I learned in the process. Stay tuned...

64-bit, virturalization, and their impact

VMWare recently released a freeware called VMWare Player that can play a pre-built virtual machine file. A virtual machine is an OS bundled with whatever the virtual machine creator put there. This is perfect for people to test-drive various operating systems and software, without going through the hassle of installing themselves. VMWare currently provides virtual machines preloaded with RedHat, Novell Suse, ubuntu, Oracle, MySql, and Bea, among others.

Memory used to be a bottleneck for virtualization software to take off. However, on the hardware side of things, both Intel and AMD are pushing 64-bit processors pretty aggressively now. With 64-bit architecture, the memory space the operating system can access increases exponentially (from 2^32 to 2^64). With the push towards 64-bit and the emergence of virtualization technology, I wonder what kind of impact this will have on the software landscape, like operating systems, database software, web server, and application server, etc..

Linux, MySql, Apache and other open source software have made great headway in enterprise server market, especially for large financial firms. I do believe there are still a big learning curve and intimidating factor at play for mid-size to smaller firms when it comes to learning and evaluating alternative software products like Linux. Maybe the combination of 64-bit and virtualization software will help. Using the cliche popularized by the book The World Is Flat, 64-bit and virtualization will help bring down barrier of entry and flatten the competitive landscape. With more memory and more powerful processor, virtualization software helps people test things out that they may not able to or too difficult for them to try otherwise. And that will be a good thing.

The current market leader in this arena seems to be VMWare, since it works on both Windows and Linux platforms. Microsoft’s Virtual PC and Virtual Server only works on Windows, and my limited testing in installing Fedora Core 2 on Virtual PC didn’t work out very well.

Software vendors, jump on the wagon. Oracle, MySql, IBM, Bea have created and provided virtual machine files for downloading at VMWare’s Virtual Machine Center. I think that is a smart move. Even Microsoft has something to gain in doing so. For example, it can team up with VMWare and distribute Sql Server 2005 for a wider testing via their distributing channels.

I have personally tried ubuntu Linux distro on my laptop and it worked pretty well. My laptop is Acer Aspire 3500 with Celeron processor and 512M of memory.

Find out uptime of server and MySql database

This site had been unstable for the last couple of weeks, due to my hosting company’s issues with servers. My Apache and MySql database have both been moved to a different server. Hopefully things will be stable from now on.

During the troubleshooting time, I used a few commands to find out the uptime of both server and MySql database. I thought these would be helpful to other people so here they are.

To find out the uptime of your Linux server, any one of the following commands will do:
w
uptime
top

To find out the uptime of your mysql demon, log into the server using mysql command line, then issue the following command:
\s

I am sure there is a way to find out how long Apache has been running, but I just don’t know. Can anybody enlighten me? Thanks.