Monday, September 17, 2012

Backing up with Percona's Xtrabackup

 Percona's backup allows for full and incremental backups and it is open source.  I tried it on a Redhat 6.2 server called Redhat62 and it worked great.   I installed a new version of MySQL and did a restore using files I had backed up using MySQL Enterprise backup and to my surprise innobackupex restored the data and it worked.  The only thing I had to do was change permissions before I started MySQL.

Here is what I did:

Create a backup user for MySQL backups.

mysql>; CREATE USER ’bkpuser’@’localhost’ IDENTIFIED BY ’password’;
mysql>; REVOKE ALL PRIVILEGES, GRANT OPTION FROM ’bkpuser’@'localhost';
mysql>; GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO ’bkpuser’@’localhost’;
mysql>; FLUSH PRIVILEGES;


To do a full backup of MySQL run this command:
innobackupex --user=bkpuser --password=password --parallel=4 --use-memory=4G /path/to/BACKUP-DIR

My backup directory on Redhat62 is /storage/backups

innobackupex reads the my.cnf file so it knows where the MySQL data is located.  

By Default innobackupex uses only 100MB for running the backup.  To increase the speed of the backup  you need to allocate more memory.  Set the "--use-memory=" to most that  you have free.

You can increase the number of threads by using the parallel parameter.

YOU NEED TO PREPARE THE DATA FOR RESTORE
After the backup is completed you need to run the "--apply-log" before you can restore the data.  The "--apply-log" replays committed transaction in the log files and rolls back uncommitted transactions.

innobackupex  --apply-log /path/to/BACKUP-DIR/time_stamp

To restore you need to run this command:  MYSQL NEEDS TO BE SHUTDOWN DURING THE RESTORE

innobackupex  --copy-back /path/to/BACKUP-DIR

I had previously had databases in the /var/lib/mysql directory with the same name.  innobackupex failed with a message.  I deleted all of the files under /var/lib/mysql and ran it again.  It completed successfully.   I guess since it is doing a full restore it doesn't write over the files that are there.  You will need to clear our all of the files in the directory to which it is restoring.

After the restore is done run this command:

chown -R mysql:mysql /var/lib/mysql


You can do incremental backups with innobackupex.  First you need to do a Full backup and then you can run incrementals.   If you are going to use incremental backups then your Full backups you will need to have the --redo-only option added to it.  This is explained in Pecona's manual:
Preparing an Incremental Backup with innobackupex Preparing incremental backups is a bit different than full
ones. This is, perhaps, the stage where more attention is needed:
• First, only the committed transactions must be replayed on each backup. This will put the base full backup
and the incremental ones altogether.
• Then, the uncommitted transaction must be rolled back in order to have a ready-to-use backup.
If you replay the commit ed transactions and rollback the uncommitted ones on the base backup, you will not be able
to add the incremental ones. If you do this on an incremental one, you won’t be able to add data from that moment
and the remaining increments.
Having this in mind, the procedure is very straight-forward using the --redo-only option, starting with the base
backup:

innobackupex --user=bkpuser --password=password --redo-only /storage/backups

To run an incremental you need to issue this command:

innobackupex  --user=bkpuser --password=password --incremental /storage/backups --incremental-basedir

What if you only want to restore 1 database or 1 table instead of the whole backup?  Here is what you need to do. 

Start up a second session of MySQL on the same server, but point it to your backup directory that is holding the data you want to restore.

To start a second session:
mysqld --basedir=/usr --user=mysql --log-error=/path/to/BACKUP-DIR --open-files-limit=4096 --pid-file=/path/to/BACKUPDIR/Time_Stamp/mysql.pid --port 3307 --datadir=/path/to/BACKUPDIR/Time_Stamp

Here is an example:
mysqld --basedir=/usr  --user=mysql --log-error=/storage/backups/mysql/mysql.log --open-files-limit=4096 --pid-file=/storage/backups/mysql/2012-09-14_10-01-55/mysql.pid --port 3307 --datadir=/storage/backups/mysql/2012-09-14_10-01-55

After you start your second session of MySQL you can now do a MySQLdump the database or table that you want to restore.

To restore a database, type this:
mysqldump -P 3307 -u bkpuser -p password databasename > databasename.sql

To restore a table, type this:
mysqldump -P 3307 -u bkpuser -p password databasename tablename > tablename.sql

I put this information from the following sources: Percona's xtrabackup pdf file found on their website,http://www.tekovic.com/mysql-hot-backup-with-xtrabackup-on-centos and  http://steveswanson.wordpress.com/2009/04/21/exporting-and-importing-an-individual-mysql-table/


Friday, June 15, 2012

Remotely copy hosts file to Windows 7


I have users that use laptops to work remote.  Unfortunately, when they VPN into to our server they can route, but they have problems with DNS.   So for these users I have a hosts file setup with the servers that they need.   Normally, I would just go to their C drive \\computername\c$  and drill down and manually replace it.   That works fine, but since I started using PDQ Deploy - From Admin Arsenal (This is a super Great application - I strongly recommend it) I wanted to see if I could deploy the hosts file to my Windows 7 Professional laptops using a batch file. 

I ran into all kinds of access denied problems.  Everywhere I searched on the Internet for help I ran into you can't it is a security feature in Windows 7.   I tried many things that I found online, but with no success.  That was until I ran into this post: http://stackoverflow.com/questions/10724591/how-to-remote-execute-an-elevated-remote-script-in-powershell.

To be honest, I didn't know what "start-process" was, but since I have googled it.  After putting together my script, I know there more efficient ways to write this script, but for a quick batch file that is easy to follow this is what I wrote.


start-process cmd.exe -verb runas /env /user:username@domainname.com
echo y |copy "\\servername\apps\misc\Windows 7 hosts file\hosts" C:\windows\temp
echo y |copy "\\servername\apps\misc\Windows 7 hosts file\hosts.orig" C:\windows\temp
echo y |copy C:\windows\temp\hosts C:\windows\system32\drivers\etc\hosts
echo y |copy C:\windows\temp\hosts.orig C:\windows\system32\drivers\etc\hosts.orig

Let me explain the script a little bit.   I didn't test, but maybe I could have copied from the network share to C:\windows\system32\drivers\etc directly, but I remember getting an error about copying from a network location, so I decided to copy to the temp directory on the computer and then copy over the original hosts file under the etc folder.   Please experiment or write better code or show me how you would have done this.    Also, I have a copy of an original windows 7 hosts file that I copy into place (the etc folder) so that if I ever need to change it or the user needs to change it while on the road it is there.   

The "echo y" just answers the questions that I do want to overwrite the original file.  I named my batch file copyhost.bat

Now that I have the script written Let's turn to PDQ Deploy and set it up to depoly the hosts file.




If you are already familiar with PDQ Deploy you know how easy it is to setup deploying files.   I just choose my batch file and include the entire directory which includes "copyhost.bat", "hosts", "hosts.orig"  and that it.  I save it and the I just deploy it by choosing deploy and then choosing which computers I want to deploy this to.  Within seconds I'm done and I have a status report saying "successful".

Let me know if you figured out another way to do this.

Tuesday, June 5, 2012

Backup and Restore using mysqlbackup from MySQL Enterprise


All this was done in a lab.  Don't do this on a production server.  There is my warning and disclaimer.

I did a full backup of my MySQL instance which resides under /var/lib/mysql.   I then delete all the data, all the ib* files, and mysql.   After deleting those files I ran a full recovers.  Here is how I did it.

Full Backup
Run the following command to do a full backup.   What this will do is backup everything in /var/lib/mysql and with the backup-and-apply-log it will go back and grab anything that has changed during the backup.   Also, that argument prepares the backup for a restore.
./mysqlbackup --user=root --password  --backup-dir=/storage/backups backup-and-apply-log
 
You need to specify a backup directory that is empty of mysqlbackup will complain.
When the backup completes you will have a message at the end telling you that it was successful.

I cd to the location of my backup and everything looked like it was there.   I ran a du -sh * and results looked the same.

Full Restore
./mysqlbackup --defaults-file=/storage/backups/backup-my.cnf --datadir=/var/lib/mysql --backup-dir=/storage/backups copy-back

Under "--default-file=" I originally put /etc/my.cnf thinking that I should use the my.cnf file I created.  However, part of the backup creates a "backup-my.cnf" with a few lines in it.  You should use this file for the restore or you could put these lines in your restore command.  It is much easier to just use the file that was created.

I started mysql /etc/init.d/mysql start, but it failed with the PID error.   I looked at my restored directory and noticed many of the files was owned by root, so I ran this command on the mysql directory.
chown -R mysql:mysql mysql

Now MySQL starts and every thing looks great.  

Thursday, May 24, 2012

Instead of Samba use Centrify

I've used samba for a long time and love it, but I ran into a product called Centrify that is so easy to setup and use for kerberos authentication against a Windows Active Directory that I don't think I'm going back to samba.

Here is a very brief explanation of how I set it up on my Linux Server.


Download Centrify Suite and the centrify samba package.

1. Uninstall your current ssh and samba.
2. Login as "root"
3. Extract the files.
4. Run "install-express.sh"
5. Answer all the questions.
6.  Reboot.
7.  Install the samba packages.


Make the following changes in /etc/centrify/centrifydc.conf file.
Change the shell from /bin/bash to /bin/ksh
Change the auto.schema.primary.gid: 100
Change the auto.schema.private.group: false

Create a group.ovr file in /etc/centrify/  Add the following line:
+domain users:users:::

Move MySQL to a different Directory


Steps I use to install MySQL to a different directory.   The truth is I just use the rpm and let it install in the default /var/lib/mysql on Redhat and then I do the following to move it to another directory.

After the install I setup my my.cnf file and then start MySQL.   I don't think it is necessary to start it, but I do so that the ib files can be created.  I then stop MySQL.   I cd to /var/lib and move the mysql directory to wherever I want.  In my case I move it to my /data directory which is on a different filesystem.

So I issued this command mv mysql /data
Then I create a symbolic link to my new mysql location by using this command:
ln -s /data/mysql mysql

Now under /var/lib/ I have a symbolic link that points to /data/mysql.   If I cd to /var/lib/mysql I will be in /data/mysql.

One reason I do this is I don't like to have data in my root partition in case I fill it up.  Also, in my setup I don't have enough room in my root partition to host mysql.

After making this change I started to get this error:
starting mysql.the server quit without updating pid file failed.   I've seen this error before and it is usually a permission issue.   I checked my permissions and the permissions were fine.  

The problem is selinux the iptables or firewall.
To check run this command:
semodule -l 

Check and see if mysql is in the list?

Now temporarily disable selinux with this command:

echo > 0 /selinux/enforce

or 

service iptables stop

Now try to start MySQL.  Did it start?  Mine Did.

Now you know the problem is with selinux.  You have a few chooses:

1. you can disable selinux by adding SELINUX=disabled in /etc/selinux/config.  The lease secure, but fastest fix.
2. You can disable the mysql module in selinux.  To disable mysql run this command:

semodule -v -d mysql  or semodule --disable=mysql

To re-enable module run this command:
semodule -v -e mysql or semodule --enable=mysql

The "-v" is verbose and is not necessary.

3. You can keep it enabled, but follow the information in this link:

Tuesday, May 22, 2012

LVM INACTIVE

After a reboot I noticed that my iSCSI LVM was missing.   I did an lvscan and it was listed, but as INACTIVE.

I ran lvchange -a y /dev/vg_nobakcup/lg_nobackup and the logical volume became active again.
I ran a lvscan to verify it was active.  
I then mounted the volume.
Upon reboot I had the same problem, so I added lvchange -a y /dev/vg_nobackup/lg_nobackup and rebooted again.   This time the volume was active and mounted.  PROBLEM SOLVED.

I believe the issue is this is an iSCSI Volume connecting to Microsoft's iSCSI Storage server.  I believe the connection just times out before connecting.  

Installing Redhat 6.2 & Linux Integration Services on Hyper-V

I installed Redhat 6.2 today.  I added Linux integration services 3.2 and after I added the service I no longer had a cdrom drive or my networks.   So this time I'm trying a little different approach.  I believe this is what I did the first time and it worked.
Before you install Redhat 6.2 add a legacy network card to your settings.   Redhat will recognized the legacy network adapter, but not the normal network adapter.

Once you have configured Redhat and it has rebooted you will have a desktop, but you won't be able to do anything with the desktop because you don't have mouse or keyboard control.  You need to install the Linux Integration Services.   Press "CTRL+ALT+F2" at the same time.   This will will give you a terminal window.  Login as root.

In Hyper-V go to Media under Virtual Machine Connection and attach the iso file as a DVD drive.

Once it is attached use the mount command on Linux to mount the DVD.

mount /dev/cdrom /media
cd to /media
run install.sh
reboot
After the reboot the clock will work, the mouse will work, the keyboard will work, the network adapter will work.   
Now you ready to use your new Redhat 6.2.
After Installing Linux Integration Services 3.2 you will no longer have a cdrom.
You will need to run this command:
insmod /lib/modules/$(uname -r)/kernel/drivers/ata/ata_piix.ko 
for the cdrom to mount.

Wednesday, May 16, 2012

Adding LVM from command line

This is how you setup a Physical Disk, Volume Group and a Logical Volume using the command line in Linux.

This example will be from a Redhat Enterprise 6.2 Installation.

So we will create a Physical Disk, Physical Volume, then a Volume Group, then a Logical Volume and then mount the volume.  Type only what is in "red".
 


Step #1 - Find out what device your new hard drive is assigned.

fdisk -l 

You should see all your disk including the one that you just added.  Here is the one that I just added.  

Disk /dev/sdb: 343.6 GB, 343597383680 bytes
255 heads, 63 sectors/track, 41773 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       41774   335544319+  8e  Linux LVM

Our new device is called "/dev/sdb1"

Step #2 - Partition the disk with fdisk. (Create Physical Disk)

fdisk /dev/sdb1
m - to see all the command options
n - to add the new partition
p - to make it a primary partition
1 - to make it the 1st partition
First cylinder (1-41773, default 1):  PRESS ENTER
Last cylinder, +cylinders or +size{K,M,G} (1-41773, default 41773): PRESS ENTER

***NOW WE NEED change the partition's system id
t - to change the partition's system type
L - to list all the system type
FOR LVM type 8e
8e - for LVM PRESS ENTER
w - to write table to disk and exit.

STEP #3 - Create a Physical Volume with pvcreate.

pvscan - will show you the physical volumes.
PV /dev/sda2   VG vg_redhat62   lvm2 [69.51 GiB / 0    free]
  Total: 1 [69.51 GiB] / in use: 1 [69.51 GiB] / in no VG: 0 [0   ]

As you can see our new physical disk does not show up.  It will show up after we create a physical volume.
pvcreate /dev/sdb1 - creates the physical volume.
 Writing physical volume data to disk "/dev/sdb1"
  Physical volume "/dev/sdb1" successfully created
pvscan - will now show our new physical volume
 PV /dev/sda2   VG vg_redhat62     lvm2 [69.51 GiB / 0    free]
  PV /dev/sdb1                      lvm2 [320.00 GiB]
  Total: 2 [389.51 GiB] / in use: 1 [69.51 GiB] / in no VG: 1 [320.00 GiB]

STEP #4 - Create the Volume Group
 vgcreate vg_data /dev/sdb1 - This creates the Volume Group.  give it a name and point it to your physical disk.
  Volume group "vg_data" successfully created
You can run either vgscan or vgdisplay to see your new Volume Group.

STEP #5 - Create a Logical Volume
lvcreate -l 100%FREE -n lg_data vg_data - This creates the Logical Volume.
  Logical volume "lg_data" created
The "-l 100%FREE" mean to use 100% of available space and "-n" is for naming.  So I called the new Logical Volume "lg_data" and pointed it to my new Volume Group "vg_data".

To check on the new Logical Volume run either lvscan or lvdisplay.
lvscan
  ACTIVE            '/dev/vg_data/lg_data' [320.00 GiB] inherit
  ACTIVE            '/dev/vg_redhat62/lv_root' [33.14 GiB] inherit
  ACTIVE            '/dev/vg_redhat62/lv_home' [28.67 GiB] inherit
  ACTIVE            '/dev/vg_redhat62/lv_swap' [7.70 GiB] inherit

STEP #6 - Format the new Logical Volume
 mkfs.ext4 -m 0 /dev/vg_data/lg_data - File type is ext4 the "-m 0" don't reserve disk space for superuser. It save 5%
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
20971520 inodes, 83885056 blocks
0 blocks (0.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2560 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

STEP #7 - Mount the Logical Volume
Create a directory that you want to mount the volume to.
mkdir data
mount /dev/vg_data/lg_data /data

These steps created a physical disk, a physical volume, a Volume group, a Logical volume, formatted the volume and mounted it.
 df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_redhat62-lv_root
                       33G  2.5G   29G   9% /
tmpfs                 2.8G  272K  2.8G   1% /dev/shm
/dev/sda1             485M   53M  407M  12% /boot
/dev/mapper/vg_redhat62-lv_home
                       29G  174M   27G   1% /home
/dev/mapper/vg_data-lg_data
                      315G  195M  299G   1% /data

As you can see are new LVM is listed last and is mounted.   

Thursday, April 26, 2012

Use secure keys to login automatically from windows



1. Using Putty login as the user you want to create the key.
2. type ssh-keygen –t rsa.


3. Now this will create two files id_rsa and id_rsa.pub under ~/.ssh
4. Now copy the id_rsa file (Private Key) to your document directory on your windows computer.
5. Use the Putty Key Generator program (right click on putty) that comes with Putty to import this file. (See step 6).



6. In the Putty Key Generator program click “Conversions”, then “import key” and choose the file id_rsa that  is in your document directory from step 4.
7. This is what it will look like.



8. Now copy the entire content of the big red box and paste it into a file in notepad, then save the file as “PuttyKey.
9. Copy the new file “PuttyKey” to the user’s home/.ssh directory on the Linux Server.
10. From the user’s home/.ssh directory on the Linux Server run this command.  “cat PuttyKey > authorized_keys”
11. Change permission on authorized_keys to 644.  “chmod 644 authorized_keys”










Now let’s get dl4term to use the Identity keys.


1. Open up dl4term.
2. Go to scripting and create a new script with these settings:











































3. Now click on SSH Options and browse to the id_rsa file that you saved on your computer in step 4











4. Give the script a name.  I called mine Login-SSH, now click “Save Script”.
5. Right click on the dl4term icon and choose properties.






6. Next to the last double quotes type in the name of the script you created.











































7. Now when you double click on dl4term it will automatically log you in.


-Jeff

Friday, February 24, 2012

Delete Network printer


I finally found out how to delete network printers in windows 7.  One way is to login as administrator’s privileges’.  That is too easy.

I wanted to be able to do it from the command prompt and logged in as a normal user.

Here is how you do it:

1      Open up a command prompt with elevated privileges.
2       From the command prompt enter this command and put the name of the printer you want to delete.

"rundll32 printui.dll PrintUIEntry /dn /n\\printerservername\printername"
remove the quotes

Friday, August 12, 2011

Use Google Apps for dual Deployment and Disaster Recover.

I have setup our Exchange Server, DNS Servers and Google Apps to Dual Deploy our email and to act as a secondary mail server.   In my opinion the best solution possible.

I looked at Google Apps before and didn't really see the potential.  Then my son in-law told me that you could use it and use your own domain with it and that got be thinking about the potential.  This is incredible.  You can have up to 50 users and each user can have 7 Gigs of space for emails.  That is more than I allow on our Exchange server.

Although I'm a big fan of MS Exchange I thought that maybe I could use Google Apps as a backup email in case Exchange fails.  I already have 1 Disaster Recovery solution in place.  I'm using Double-Take at a remote site to replicate our Exchange server.  Some would fill this is enough, but with Google Apps I have a complete solutions.

Here is what Google Apps offers me:

When our Exchange Server goes down and it does.  I don't have to fail over to the Disaster Recovery Site immediately.  Google Apps gives me time since the email will continue to flow to Google Apps we can continue to do business as usual.  I then have time to determine how serious the problem is, how long the Exchange server will be down and if we should fail over to our Exchange server at the Disaster Recovery Site.

I have a place for all the users email to be autoachive.  If they delete something on the Exchange server they can retrieve it on Google Server.

Here is how you setup Google Apps to Act as a Secondary email server and as an archive server.

1. You need to setup a Google Apps Account.  Choose the Standard Account if you have less than 50 users.  http://www.google.com/apps/intl/en/group/index.html
2. Once you enter your domain name or purchase the domain name then you need to verify that you are the administrator.  This can be a little tricky if you are using a production domain name.
3. Fortunately for me I have my own DNS servers so I was able to make the changes.  I used the html method to authenticate.   I setup my CNAME so that I could type docs.domain.com and it would go to the google docs website and I added the google MX host information to my MX records.  Now, you can either put them first and remove your current entry or you can get them the same values as your current email servers.  You will not be able to verify until Google see them as the top MX records.   I moved my current MX record to a higher value to verify my domain.  After my domain was verified I gave my current MX records a lower value so they were first.   For my sub-domain authentication I gave the google MX record the same value as my current MX records and google verified my sub-domain.
4.  Now I did the same thing to my internal DNS so that from my PC I could resolve the MX records from within my company.
5.  So in my CNAME I use that to give shorter URL to connect to my google sight.  The way I don't have to type the www.google.com/a/domainname.  Instead I can type email.domainname.com or docs.domainname.com.   In my MX records I have my subdomain that I setup at Google Apps with the same value as my MX records for my Exchange servers.  Ex:
@ mail.domainname.com. 10
gmailalias ASPMX.L.GOOGLE.COM.
@ mail2.domainname.com 20
gmailalias ALT1.ASPMX.L.GOOGLE.COM. 20

Don't forget your "." after FQDN

This provides the ability to use DUAL - Deployment by way of the Alias "gmailalias".  There are more steps to getting this to work.  I'll explain those below.


6. To get emails to go to my Google Apps email if exchange goes down you need to add Google to your MX record as secondary email servers.  Below the enters above I have the Google Apps MX records.  In other words, if Exchange goes down the next MX record will be used to delivery mail for "domainname.  I'm not talking about the alias emails.  I don't get emails coming to me with the alias domain, that is used to forward emails to my Google emails.  So in my case the next MX record for my "domainname" is "mail-Dr" with a value of 20.  Well, my "mail-DR" isn't setup to receive email only to receive replication and I would need to manually failover and start the services before I would receive any emails.  So then the next MX record would be the google account.  So here are the Google MX records.




http://www.google.com/support/a/bin/static.py?page=guide.cs&guide=22229&topic=22230

Monitor MySQL queries in Real Time

Just a quick tip on monitoring the queries that mysql is handling on a production site. You can use the mysqladmin tool to return a list of the processes currently being handled. Combining this with the UNIX watch command allows a real-time monitoring of what's going on.
watch -n 1 mysqladmin processlist
The "-n 1" specifies that mysqladmin executes every second. Depending on your set-up, you may need to specify a mysql user and password:
watch -n 1 mysqladmin --user= --password= processlist

LVM Snapshot script

LVM Snapshot script
Used for copying a MySQL schema to a test environment


There are so many ways to do this, but our need was to not have any production down time* and have the test database available ASAP.  

I wrote up a little how to and I thought I might share it so others could use it.  Like I said there are many ways to do this so just take a look and use the logic that works for you. 

A Method to copy Data to a test environment


This method will copy all data in a volume and MySQL a test environment with no downtime.  The method used could also be used for backing up data or replication.
Here are the steps needed to accomplish the copy to test.
1.       Add an additional hard drive for Storage. 
2.       Configure the disk using fdisk and then create a Physical Volume with the pvcreate command.*
3.       Add the Physical Volume to the VolGroup with the vgextend command.*
4.       Setup MySQL to run a second instance.*
5.       Run the this script.

#! /bin/sh

user=username
pwd=password
olddb=originalname
newdb=newname
socket=/tmp/mysql.sock2

#This will remove LVM and stop the second instance of MySQL .
mysqladmin -u$user -p$pwd --socket=$socket shutdown 
sleep 4
umount /dev/VolGroup01/databackup
lvremove -f /dev/VolGroup01/databackup

#This will flush mysql and Lock Tables and LVM snapshot (see below)**
mysql -u$user -p$pwd < lvm_snapshot

#At this point the volume and MySQL files have been copied

#This will will mount the LVM snapshot to /mnt/databackup
 mount -t ext3 /dev/VolGroup01/databackup  /mnt/databackup

#This will start the second instance of MySQL on port 3305
mysqld_multi start 2

#This is needed to allow enough time for MySQL to start and create the mysql.sock2 file
sleep 4

#This will login to the second instance of MySQL and rename the schema to dl4test. 
mysqlconn="mysql -u$user -p$pwd -S $socket -h localhost"

$mysqlconn -e "CREATE DATABASE $newdb"
params=$($mysqlconn -N -e "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='$olddb'")

for name in $params; do
      $mysqlconn -e "RENAME TABLE $olddb.$name to $newdb.$name"; done;

$mysqlconn -e "DROP DATABASE $olddb"

#This will grant user saitest access to the newdatabase schema
$mysqlconn -e "GRANT ALL PRIVILEGES ON newdatabase.* TO 'username'@'%' IDENTIFIED BY 'saitest'";

This script takes about 10 seconds to run and requires no down time in production.  
Note: the schema name change does not change any stored procedures so a script or logic would need to be added in order to create those after renaming the schema.

*More Information on Setup:
1.  Use fdisk to setup the disk. 
Type fdisk /dev/sdb1 (or whatever device your new hard drive is) and press Enter.  Then press, m,n,e(choose the defaults), p, and w to save the changes.  
2.  Create a Physical Volume.
Type “pvcreate /dev/sdb1”
3. Extend the Volume Group.
Type “vgextend VolGroup01 /dev/sdb1”

4. Add a second instance of MySQL.
Modify the /etc/my.cnf with the following changes.
a.       Add a [mysqld_multi] section that looks like this:
[mysqld_multi]
mysqld          = /usr/bin/mysqld_safe
mysqladmin      = /usr/bin/mysqladmin

b.      Rename [mysqld] to [mysqld1]
c.       Add a [mysqld2] section with the following parameters:
[mysqld2]
port            = 3305
datadir         = /mnt/databackup/mysql
socket          = /tmp/mysql.sock2
pid-file        = /mnt/databackup/mysql/mars-snapshot-test.pid2
log_error       = /mnt/databackup/mysql/error2.log
To start the second instance of mysql use the following command:
“mysqld_multi start 2”
To stop the second instance of mysql use the following command:
Mysqladmin –uusername –ppassword –socket=/tmp/mysql.sock2 shutdown.
To login to the second instance of mysql you will need to login using the socket:
Mysql –uusername –ppassword –S /tmp/mysql.sock2 –hlocation

DownTime - we run this at night when there are a minimal of users. 
Long queries at the time of the LVM snapshot will call some downtime.


** Here is the content of the lvm_snapshot file
FLUSH TABLES WITH READ LOCK;
system lvcreate -L 220G -s -n databackup /dev/VolGroup01/LogVol01;
UNLOCK TABLES;
QUIT





Thursday, June 3, 2010

Error 126, 1068, 70020 unable to VPN

I had an employee with the following problem.  They were unable to VPN and were receiving the errors in the Title.  They were also unable to connect to some wireless AP at customer's site.   Here is what I did.  One i stopped Eset from Scanning the C:\windows\system32 directory.   This allowed the Windows Remote Management Access service to start.   I then looked at HKEY_LOCAL_MACHINE\System\Services\RASMAN\PPP\EAP and noticed that Symantec had entry in 13,25, but not 26.   I read somewhere to delete all entries except these 3 because they are windows default entries.  Since Symnatec (Symantec was installed on this computer, but removed) had entries in I decided to delete 13 and 25.  I deleted them and then rebooted hoping they would self populate, but they did not.

I then exported these registry entries from another Vista computer and then imported them.  The problem was now fixed.
 

Tuesday, February 16, 2010

I was struggling trying to get Outlook 2007 to connect to my Exchange 2003 server...

Here is what I did.

I was trying to add a new user, but I continued to get a message that Exchange was unavailable or offline.  Yet, no one else was complaining and I could connect using OWA.   So I figured it was a problem with the client computer. 

Where it prompts to put in the Exchange Server name I put in the Domain Controller name instead.  This quickly resolved to the name of the exchange server and then I was connected.   I was able to finish setting up the new user.   So I could resolve the name by going to the DC instead of the exchange server.  Time to look at the services on the exchange server.  I noticed that the Microsoft Exchange System Attendant had stop running.  This is needed to resolve Active Directory information.    So if you run into this problem make sure this services is running.  

Thursday, June 18, 2009

How to remove a GPT Partition

I bought a USB hard drive and it was formatted for apple with the GPT partion.  My windows XP machine recognized the hard drive, but not the partition.  I had to format the drive, but was unable to through the Disk management console or in the usual way.

Here is what you will need to do:

type the following command at the command prompt.

1. cmd
2. diskpart
3. list disk
4. select disk x (choose the disk you want to format)
5. clean
6. exit

You are now ready to format the disk in windows.

Thursday, June 11, 2009

How to change the IP Address in SCO Unix

cd to /var/spool/lp/admins/lp/interfaces
vi the printer that you want to change the IP Address.
Look for the line: PERIPH=xxx.xxx.xxx.xxx (example PERIPH=192.168.1.24)
Change the IP Address to whatever you want.

****If your printer was on a HP JetDirect then check to make sure the PORTNO=9100****

After you make the change, then save the file.

disable the printer with this command:
disable printername
Then enable the printer with this command
enable printername

You should be able to print to the printer with the new IP Address.

Wednesday, June 10, 2009

Log interactive session in MySQL

There are two ways to start recording your interactive session in MySql.

1. From the Command line:
(I'm only typing the command "mysql" and will assume that your username and password is saved in your home directory in ".my.cnf" file.

mysql --tee=filename database
ex: myssql --tee=tmp.txt dl4demo09

2. From within Mysql:
mysql> \T output.file
Logging to file 'output.file'

Thursday, August 7, 2008

How to confiure an IPhone to use Exchange

I struggle to get the president of our company Iphone to work with our windows 2003 server. 
I used this document to setup the IPhone.
http://support.apple.com/kb/HT2480
The phone validated and appeared to be working fine, but no email, calendars or contacts would appear in the phone.  Although phone would report that it was updated.

I realized that I was getting an error when I tried from a browser to hit https://registerdomainname/oma
I found this article below that I tried first.  I was able to connect to the server just fine.  However, I realized that I was not requiring SSL connections.
http://support.microsoft.com/?id=883380
Once I enable require ssl connections I had the same error.  I looked a little further and found this document that solved the problem.
http://support.microsoft.com/kb/817379

Friday, June 27, 2008

Upgrading Hyper-v to the final release wasn't as smooth as I thought it would be.

I was a little surprise that the upgrade wasn't as seamless. I followed the instruction from http://support.microsoft.com/kb/950050, but still had issues. After the upgrade, I couldn't start any of my VMs. I had to delete and create new ones. Then my network adapter was removed, so I had to create a new network adapter. My VM finally came up, but the mouse didn't work, so I had to install the new integration services. I just finished that. My system is rebooting, so I'll see what other problems I'll run into.

Thursday, June 5, 2008

How to mount a vhd file to the host

Why would you want to do that? Well there are many reasons, but most important is to get to the data.

Here is how I do it.

I use Ben's script
http://blogs.msdn.com/virtual_pc_guy/archive/2008/02/01/mounting-a-virtual-hard-disk-with-hyper-v.aspx

I just edit the script and put in the drive, path and filename of the vhd that I want to mount. After editing and saving I double-click on my vbs file and it is mounted. I have one called mount vhd.vbs and one called unmount vhd.vbs. The only difference is the two scripts is the last line VHDService.Mount(VHD) to mount andVHDService.unMount(VHD) to unmount.

I then open up Disk Management under computer management. You should see a volume that is offline. Right click on choice "online". The disk will come on line and be assigned a drive letter. That's it. Now just go into explore and take a look at the disk.

Update - How to backup Virtual Server in Windows 2008

I've made some changes to how I backup my Virtual servers. The other way I wasn't able to copy over the previous backup so I wasn't get the lastest backup. Here is what I am doing now.

I have 3 files that I use.
1. script.dsh
Here's the content of it.
#DiskShadow script file
set context persistent nowriters
set metadata c:\diskshadowdata\example.cab
set verbose on
begin backup
#add volume c: alias SystemVolumeShadow
add volume d: alias DataVolumeShadow

create

#expose %SystemVolumeShadow% r:
expose %DataVolumeShadow% p:
exec c:\diskshadowdata\backupscript.cmd
end backup
#End of script

As mentioned in the previous post I explained where I got this and what changes I made. The only difference from the previous post is that I'm using the P drive instead of the Q drive.

File #2 - backupscript.cmd
I:
rmdir /S /Q backup
mkdir backup
cd \backup
P:
xcopy /E /Y "virtual servers" I:\backup\
mountvol P:\ /D

After the first file creates the shadow copy of my D drive and mounts it on the P drive, I use this file to remove the previous backup (because I don't have room and for some reason it was not overwriting the previous backup) and then copy the virtual servers.
There are definitely better ways to do this, but here is what this script does.
I change to the I drive which is the drive my USB hard drive is mount to. I then remove the directory that contains the previous nights backup. I don't have room on the USB drive to house more than one backup. I then create the same directory to put the backup virtual files in. Then I switch to the P drive which has the latest mount shadow copies in and start copying just the directory that contains the virtual server files. That directory is called "virtual servers". After the copy is done then I unmount the P drive. If you don't then you will not be able to successfully run the first script the next time you run it.

File #3 - Backup.bat
C:
cd \diskshadowdata
diskshadow /s script.dsh

This file is the one that I have the task scheduler setup to use for the nightly backup. Because I don't have my pathing setup I just cd to the diskshadow directory which has all three files in and run the "diskshadow /s script.dsh" command.

I hope I didn't confuse you.

Ask if you have any questions and I will try to explain better.

Friday, May 23, 2008

Backing up volume shadow copies in Windows 2008 (Hyper-v) Virturals using Diskshadow

The script I had for backing up my Windows 2005 Virtual server does not work in Windows 2008 using Hyper-v. So I started looking for another solution. Here is what I'm doing to backup my Virutal servers in Windows 2008. In Windows 2008 there is a new tool called "diskshadow". This link below shows how to use it and they have a script to get your started.
http://technet2.microsoft.com/windowsserver2008/en/library/e962537d-b759-4368-b6f1-e8391cf7b2211033.mspx?mfr=true
I don't need to create a shadow copy of my system drive nor to mount it, so I just commented out the two lines:
#add volume c: alias SystemVolumeShadow
#expose %SystemVolumeShadow% p:

For testing I run this command from the command prompt: DISKSHADOW /s script.dsh
If all is well I set up a task schedule to run this.

So what this script does is create a shadow copy and mounts it to the P and Q drives. I don't need the mount to P so my script will only mount my shadow copy of my D drive to Q. I then have a script that runs an xcopy command to backup my "virtual servers" folder to my USB hard drive which is mounted to the I: drive.

The last line of my backup script is to remove the Q: drive mount. If you don't remove the mount before you run the script you will get an error. So unmount the shadow copies that are mount before running the script. To unmount use this command. "mountvol driveletter:\ /D"

So the last line in my backup script I have "mountvol P:\ /D" so that the P: drive is available the next time I run the script.dsh the P: drive is available to mount to.

Tuesday, May 6, 2008

Here is how to change a Windows KMS license to a MAK license.

First run this command from a dos prompt and put in your MAK license Key.

slmgr -ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
http://support.microsoft.com/kb/929826/

Next. Go to system's properties in the control panel and click on activate windows now. After click on it you will activate it with a MAK license.

Friday, May 2, 2008

Force removal of a domain controller

I tried to remove a domain controller today from a virtual environment and was unable to. I found this article that shows you how to force the removal of the domain controller.
http://support.microsoft.com/kb/332199

Friday, April 25, 2008

Upgrade Window's virtual host server from 2005 to 2008

I found out that when you upgrade from Windows Virtual server 2005 to Hyper-v you want to remove the vmadditions from your windows maching prior to moving them to the Windows 2008 server that has hyper-v installed. It is alot easier.

I have mouse problems when I just moved a MS 2005 Virtual Server to Windows 2008. When I removed VMaddition, I didn't have the mouse problems. It was alot easier to upgrade the hyper-v guest components.

Double-Take Invalid License when you upgrade to Windows 2008

My host system has 4 virtual servers on it. When I upgrade the host from Windows 2003 to Windows 2008 I now get an invalid license error in Double-take. I'm on hold right now. When I get the problem resolved I will tell you what they had me do. I'm hoping that they just issue me a valid license for this. We'll see.

Well, I just spoke to Mike Brown. He said that it appears that Double-take is determining that with Hyper-v guest components that it is a physical server instead of a virtual one. He gave me a 6 day key until they could resolve the issue. They will get back to me.

Double-take are really good at support. You can talk to someone that speaks english and they are pretty knowledgeable.

Friday, April 18, 2008

How to create a shadow copy and mount it.

To create a shadow copy run this command.
vshadow -scsf D:

To list the shadow copies run this command.
vssadmin list shadows

To mount to a directory run this command:
mountvol D:\mountpoint \\?\Volume{21bf079c-f9db-11dc-b4a5-0015173b1ee7}\

You could also mount it to a drive using the vshadow command.
vshadow.exe -el={ShadowID},Driveletter:
example: vshadow.exe -el={4cdd0ee7-6448-4ab7-9c55-576c9dd9d41d},P:


To remove the mountpoint from the directory run this command.
mountvol D:\mountpoint /d

Wednesday, April 16, 2008

Terminal Server 2008 doesn't like it when you change the name of the server

I have Windows 2008 setup with Terminal Services running really well. I then changed the name of the server and Terminal server doesn't want to work anymore. The Event Log is suggesting that it is not running. However, it is running. So I uninstalled it and reinstalled it with a new certificate, but still no luck.

I haven't been able to find an answer for this one. I guess uninstall terminal services before change the name and then reinstalled it afterwards.

I can use SteadyState for the Kiosk

Microsoft has introduced SteadyState for locking down computers so the public or users don't ruin them. You can reset them.

I read an article today about it in the January technet magazine page87. I will build a virtual XP machine to try it out. I'll write more once I get it setup.

This is how I'm backing up my Virtual Servers

I've been trying to figure out a way to backup my virtual servers unto a External USB Hard drive. This server will be our disaster recovery server and the facility where it will be hosted does not do backup tapes. So I wanted a way to back to a 1TB hard drive. I thought about the online backups, but they were going to be too expensive for the size that we have and toooooooo slow. Have you every tried to restore from one of those sites? I've had customers do it and it takes forever.

I looked at many scripts that our out there. Most caused my VM to hang. The one that I settled on is from: http://blogs.msdn.com/adioltean/archive/2005/01/20/357836.aspx
His name is: Adi Oltean

His script creates a Shadow Copy and mounts it to a Drive. For instance, his script will take a shadow copy of my D: drive where my Virtual Servers reside and mount them to my H: drive. I don't have an H: drive normally, but his script will mount this volume(Shadow Copy) that is created to whatever drive you select that is not already in use.

From there you can go to your H: drive or whatever drive you selected and view copy of your Virtual Servers.

This is great. From here I copy the files to my USB Hard drive which I have mounted as my Q: drive. Because the files that are now on H: are not in use, you can copy them without any file in use errors.

Here is what I've done.
I created a small script that start off my unmounting the volume from H: that was created the night before. I then call for Adi Oltean's script to create the Shadow Copy and mount it to my H: drive. Then I start a xcopy command to copy it over to my backup folder on the Q: drive. Remember the Q: drive is my external USB Hard drive.

@echo This will remove the mounted volume.
mountvol H:\ /D

@echo This script will create a shadow copy and mount it to H:
createshadow.cmd D: H:

@echo This will copy the Virtual Server to Q:\backup.
H:
xcopy /E /Y "virtual servers" Q:\backup\

So on my D: drive I have my script which is the one above that I call backupVMs.bat and Adi Oltean's script createshadow.cmd. I setup the task scheduler to run every night. It takes about 6 hours to backup my approximately 660 Gigs.


How to Activate a sprint Cell phone for Free

I wanted to replace a phone that was dead with one that my company let me borrow until the one that I ordered on ebay arrived. Here is what I did.

First go to this website: http://www4.sprint.com/WLSApp/esnswap/do/Welcome?id12=UHP_AlreadyCustomer_Link_ActivateYourPhone

Put in your cell phone number and click "Continue"

Login in with your username and password. If you haven't setup an account you will need to.

After logging in you will need to select your phone and click on "Upgrade or Active Phone". The box will open and then click on "Activate".

Once your click on "Activate" You will receive warning that the current phone will no longer be able to make or receive calls, etc.

That's ok. You want to replace it anyways.

You will be taken to a webpage that has information about your cell phone. Print it out because you will need it.

For my Cell phone, I was given a code that allowed me to get into the configuration menu.

From there I went into the Basic Menu and I put in my MDN/PTN. Which is my 10 digit cell phone number. Next I had to put in my MSID/IMSI number. I believe this is the 10 digit cell phone number from the main phone number on the account. The webpages shows 5 zeros before the number. Just ignore those and put in the last 10 digits. Next it will ask for the SID/BID number. The webpage shows 5 digits, but drop off the "0" and put in the last 4 digits. Press "Ok" or "END". When the phone comes up it will be on the Sprint Network. You should be able to make and receive phone calls.

Now, if you have problems. You can call 1.877.345.7895 for help. The tech will help you. This may be a better options for most people.

Monday, April 14, 2008

Unable to connect to Virtual Servers using VMRCPLUS

I've had this happen a couple of times. I tried to connect to the server using VMRC PLus and it would just hang. Here is what I've done to fix the problem.

1. Stop the Virtual Server services. You may need to use task manager to kill off the VM processes.

2. Navigate to C:\documents and Settings\All Users\Application Data\Microsoft\Virtual Server\Virtual Machines\

3. Move or delete all of these files. I usually just move them to another folder, but then later I delete them.

4. Now start the Virtual Server service

5. You should be able to connect to the server using VMRC Plus.

6. After you connect your virtual servers will be missing. Don't worry, just add them back.

7. Click on "Virtual Machines" and then "add".

8. Drill down to where you keep the Virtual servers and add each one back. They will be intact and should startup without any problems.

Good Luck.

Friday, March 14, 2008

Upgrade MySQL from 4.1 to 5.1 Linux

How to Upgrade from MySQL 4.1 to MySQL 5.1

I downloaded the files.

MySQL-server-community-5.1.23-0.rhel4.i386.rpm
MySQL-client-community-5.1.23-0.rhel4.i386.rpm
MySQL-shared-compat-5.1.23-0.rhel4.i386.rpm
MySQL-devel-community-5.1.23-0.rhel4.i386.rpm
MySQL-shared-community-5.1.23-0.rhel4.i386.rpm

Put them in a directory. I put mine in /tmp/mysql directory

First create a backup of the current Data.

Note: When doing multiple databases be sure to include the “s” at the end of databases. When doing a single database then only type database without the “s”.

To create a complete backup of all the databases do this:

# mysqldump –u root –p –-all-databases> alldatabases.sql

Or to compress the file do this:

# mysqldump –u root –p –-all-databases |gzip > alldatabases.sql.gz

 
To create a backup of individual database then do this:
 
# mysqldump –u root –p -–database database > databasebackup.sql
# mysqldump –u root –p -–database database1 > databasebackup1.sql
# mysqldump –u root –p -–database database2 > databasebackup2.sql

Or to compress the file do this:

 
# mysqldump –u root –p -–database database |gzip > databasebackup.sql.gz
# mysqldump –u root –p -–database database1 |gzip > databasebackup1.sql.gz
# mysqldump –u root –p -–database database2 |gzip > databasebackup2.sql.gz
 
If you want to backup multiple database to one file then do this:
# mysqldump –u root –p -–databases database database1 database2 > databasebackup.sql
 
Or to compress the file do this:
 
# mysqldump –u root –p -–databases database database1 database2 |gzip > databasebackup.sql.gz
 
You can also just backup the database tables with NO DATA.  This will just keep the table structure, but NO DATA.   Don’t run this on “mysql” database.  You will need the users and authentication to get back in.   Use this command:
 
# mysqldump –u root –p -–no-data -–database database > databasestructure_nodata.sql
 
To do multiple database use this command:
 
# mysqldump –u root –p -–no-data -–databases database database1 database2 > database3structure_nodata.sql
 
Once the data is protected then you can do the upgrade.
 
service mysqld stop
rpm -Uvh --nodeps MySQL-server-community-5.1.23-0.rhel4.i386.rpm
rpm -Uvh MySQL-client-community-5.1.23-0.rhel4.i386.rpm
rpm -Uvh MySQL-shared-community-5.1.23-0.rhel4.i386.rpm
rpm –Uvh MySQL-shared-compat-5.1.23-0.rhel4.i386.rpm
rpm -Uvh MySQL-devel-community-5.1.23-0.rhel4.i386.rpm
vi /etc/my.cnf
# Comment out the base-dir line under [mysqld.server] - RHEL 4 / MySQL bug
adduser mysql
cd /var/run
mkdir mysqld
chown -R mysql:mysql /var/run/mysqld
chown -R mysql:mysql /var/lib/mysql
service mysql start
mysql
 
Now you will need to fix the table structure problem with this command:
 
# mysql_upgrade –u root –p
 
You will probably see some errors about our databases.  That should be ok.  
 
Then login with the credentials.
 
If things go wrong and you need to restore; here is how to restore the data.
 
# mysql -u [username] -p [database_to_restore] < [backupfile]
 
You have to create the database first if it doesn’t exist already.  Here is the command to do that:
 
# mysqladmin -u USERNAME -p create DATABASE 
 
OR you can create it within MySQL
 
# mysql –u root –p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.1.23-rc-community MySQL Community Edition (GPL)
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> CREATE database database1;
Query OK, 1 row affected (0.02 sec)
 
To see all the databases in MySQL issue this command from within MySQL
Mysql> SHOW databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| database           |
| database1          |
| database2          |
| database3          |
| mysql              |
| test               |
+--------------------+
7 rows in set (0.00 sec)