Skill Level : Beginner
In this post, I will explain how to convert an add-on domain to a primary domain. Considering a complex case, lets consider the primary domain should be a different one from the one that holds the Add-on domain.
Pre Requisites
Server Platform : Linux
User requires : cPanel and SSH access (root)
This is a Site transfer. Also both the sites I’ve mentioned here is on same server.
Case
The Add-on Domain under a website has to be converted as its Primary Domain. If you have a Full backup, its another case. I’ll explain it in another post.
Solution
Lets consider the Add-on Domain is addon.com under the user admin and the document root of the add-on domain is :
/home/admin/public_html/addon
Now it should be transferred as the Primary Domain
* Using WHM Create a New account primary.com, the document root is then say /home/primary
We’ve to transfer the whole data from /home/admin/public_html/addon.com to /home/primary/public_html first.
* The Steps will be :
root@server [/home/admin/public_html/addon]# cp -r ./* /home/primary/public_html
This will recursively copy everything inside the PWD to the specified location
(Read the rest of this entry…)
This backup script is actually a small modification of another backup script available in Google. I am not able to get that URL to mark/link reference. Only modification I added is a four liner to remove a week old backup automatically. You may also see http://www.supportsages.com/blog/2011/05/applying-wildcards-in-grant-option-of-mysql/ as well. Indenting in python is lost, will fix tomorrow
#!/usr/bin/env python
import ConfigParser
import os
import time
# Variable Definition
username = 'cpdbbackups'
password = 'p@ssw0Rd'
hostname = 're.mo.te.ip
backupfolder = '/home/dbbackups/servername'
filestamp = time.strftime('%Y-%m-%d-%H')
deletetime = time.time() - 7 * 86400
# Delete old files
for backup_file in os.listdir (backupfolder):
full_file_path = os.path.join(backupfolder, backup_file)
if os.path.getmtime(full_file_path) < deletetime:
os.unlink(full_file_path)
# Get a list of databases with :
database_list_command="mysql -u%s -p%s -h %s --silent -N -e 'show databases'" % (username, password, hostname)
for database in os.popen(database_list_command).readlines():
database = database.strip()
if database == 'information_schema':
continue
filename = "%s/%s-%s.sql" % (backupfolder, database, filestamp)
os.popen("mysqldump -u%s -p%s -h %s -e --opt -c %s | gzip -c > %s.gz" % (username, password, hostname, database, filename))
Continue Reading
We had this particular requirement of creating a database user to be used to backup only the cPanel databases. Only recently the database mapping has been introduced by cPanel which allows the clients to create databases without the _ . However on all our client servers, we insist to have the old style with every database has Prefixing On.
Creating the database user to backup only the cPanel databases, means matching the databases with an underscore (_) in its name and that resulted in this particular SQL command to be executed as root user.
GRANT ALL PRIVILEGES ON `%\_%`.* TO `cpdbbackups`@`re.mo.te.ip` IDENTIFIED BY 'p@ssw0Rd' WITH GRANT OPTION;
Read more about the cPanel’s DB mapping at http://www.cpanel.net/blog/integration/2010/05/more-details-about-db-mapping.html
Continue ReadingIn this post, I’ll explain some basic MySQL tips that would be very useful for beginners
Reset MySQL root password
Log in as Root and Stop the MySQL daemon. Then Start the MySQL daemon and skip the grant tables which store the passwords.
# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables
# mysql -u root
mysql> use mysql;
Now you should be able to connect to mysql without a password. If not, it might be some other issues. Execute the command to reset the password
mysql> update user set Password=PASSWORD('new-password') where user='root';
mysql> flush privileges;
mysql> exit
After this you need to kill the running mysqld and restart it normally.
Creation of MySQL database, user and access rights
It should be very easy to create a database through cpanel or some other panel. But if you are on your own with only Shell access, try this :
# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;
Or you can use
mysql> grant all privileges on databasename.* to username@localhost; mysql> flush privileges;
MySQLdump and Restore
The mysqldump client is a database backup. It can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server). The dump typically contains SQL statements to create the table, populate it, or both.
Creating a Mysqldump is quite easy. If you know the database name, say database :
# mysqldump database > database.sql
When restoring a Database, make sure you login as the user. In other words, do not restore a database with root privileges. It may cause real damage. Assuming that you are logged in as the user
<strong> </strong> mysql> use dbname; //Which is the database which the backup has to be restored to mysql > source olddb.sql; //Backup
Repair a corrupted Database
Switch to the database directory which is having issues with, Like :
# cd /var/lib/mysql/database
Stop the MySQL server
# /etc/init.d/mysql stop
Check the tables
# myisamchk *.MYI
Repair the tables
# myisamchk -r *.MYI
Start the MySQL server
# /etc/init.d/mysql start
phpMyadmin
phpMyAdmin is an open source tool written in PHP intended to handle the administration of MySQL over the World Wide Web. It can perform various tasks such as creating, modifying or deleting databases, tables, fields or rows; executing SQL statements; or managing users and permissions.
If you are having a cPanel or WHM interface, its quite easy to manage a database. In cPanel interface, go to Databases section
This is the main phpMyadmin page.
In WHM, at SQL Services you can perform a variety of options. As mentioned earlier, the database repair option (for corrupted databases) can be performed here also. Access the option ‘Repair a Database’
Select the Database name and Click Repair Database.
These are quite simple tasks associated with MySQL operations.
Continue ReadingOn a cPanel server, I ran /scripts/installruby which updated the ruby version from 1.8.6 to 1.8.7
ruby -v ruby 1.8.7 (2009-06-08 patchlevel 173) [i686-linux]
But when updating the gems and the gem itself, we were getting error as below,
gem update --system
Updating RubyGems...
ERROR: While executing gem ... (Gem::RemoteSourceException)
HTTP Response 302 fetching http://gems.rubyforge.org/yaml
Solution was to specify another source as below, which was the 302 redirection of http://gems.rubyforge.org/yaml . May be gem now handles the 302 redirection properly.
gem install rubygems-update --source http://production.s3.rubygems.org/
followed by the gem update itself.
sudo gem update --system --source http://production.s3.rubygems.org/
To add the source permanently, use the command below and for more help
gem help sources
gem sources -a http://production.s3.rubygems.org/Continue Reading