<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ali Qureshi&#039;s Blog &#187; Webmaster Tasks</title>
	<atom:link href="http://www.parorrey.com/blog/category/webmaster-tasks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.parorrey.com/blog</link>
	<description>random bits on web development</description>
	<lastBuildDate>Thu, 09 Sep 2010 10:45:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://www.parorrey.com/blog/?pushpress=hub'/>
		<item>
		<title>Backup your MySQL databases automatically with cron job</title>
		<link>http://www.parorrey.com/blog/webmaster-tasks/backup-your-mysql-databases-automatically-with-cron-job/</link>
		<comments>http://www.parorrey.com/blog/webmaster-tasks/backup-your-mysql-databases-automatically-with-cron-job/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 12:49:29 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[Webmaster Tasks]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=179</guid>
		<description><![CDATA[Taking backup databases is a routine for every webmaster. Make your life a little easier by delegating this boring but extremely important chore to the shell script that will do this automatically and silently everyday, or whatever time you choose, for you For automatic MySql database backup, please use following script to take backup using [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/web-hosting/copying-files-from-remote-server-to-another-server-through-ssh/' rel='bookmark' title='Permanent Link: Copying files from remote server to another server through SSH'>Copying files from remote server to another server through SSH</a></li>
<li><a href='http://www.parorrey.com/blog/project-management/ten-step-guide-to-install-redmine-project-management-application/' rel='bookmark' title='Permanent Link: Ten Step Guide to Install Redmine project management application'>Ten Step Guide to Install Redmine project management application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fwebmaster-tasks%2Fbackup-your-mysql-databases-automatically-with-cron-job%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fwebmaster-tasks%2Fbackup-your-mysql-databases-automatically-with-cron-job%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Taking backup databases is a routine for every webmaster. Make your life a little easier by delegating this boring but extremely important chore to the shell script that will do this automatically and silently everyday, or whatever time you choose, for you</p>
<p>For automatic MySql database backup, please use following script to take backup using cron job by setting inside cPanel. Create a file named &#8216;db-backup.sh&#8217; in home/cpanelUser/ with correct permissions/ownership.</p>
<p>Place this file on this location &#8216;/home/cPanel-User/db-backup.sh&#8217; where cPanel-User is username of account.</p>
<p>Put the following code in the file db-backup.sh:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#/bin/bash</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqldump -–<span style="color: #007800;">user</span>=Database_User -–<span style="color: #007800;">password</span>=<span style="color: #000000; font-weight: bold;">*****</span> -–databases Database_Name <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>cPanel-User<span style="color: #000000; font-weight: bold;">/</span>Database_Name-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">`</span>.sql.gz</pre></div></div>

<p>Where &#8216;Database_User&#8217; is the database user, &#8216;Database_Name&#8217; is the database name and &#8216;*****&#8217; is the password of database user<br />
+%Y%m%d%H%M is the time stamp, </p>
<p>The backup file will be created under directory &#8220;/home/cPanel-User/&#8221;.</p>
<p>Now, you need to add cron job. You can do it with the help of your control panel.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>cPanel-User<span style="color: #000000; font-weight: bold;">/</span>db-backup.sh</pre></div></div>

<p>Make sure you have permissions to run this script and you can test it by going to shell, and just run the script manually. If it runs successfully, you have your Database dump at the specified directory.</p>
<p>The above cron job will executes every day at 00:00 hour and creates backup file for your MySQL Database.</p>
<h2>How to Exclude specific table from MySQL Dump script using &#8211;ignore-table option</h2>
<p>There will be times when you do not want one or some of the tables from the database(s) not to be included in the backup dump, You can easily exclude them from the dump by adidng following Option:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">--ignore-table</span> database_name.table_name</pre></div></div>

<p>By adding ignore table option, your backup dump script will become:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#/bin/bash</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqldump -–<span style="color: #007800;">user</span>=Database_User -–<span style="color: #007800;">password</span>=<span style="color: #000000; font-weight: bold;">*****</span> -–databases Database_Name <span style="color: #660033;">--ignore-table</span> database_name.table_name <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>cPanel-User<span style="color: #000000; font-weight: bold;">/</span>Database_Name-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">`</span>.sql.gz</pre></div></div>

<h2>Running a .sh: Permission Denied Error</h2>
<p>If you have uploaded <b>db-backup.sh</b> as suggested in this article, there&#8217;s good chance that you will run into this <b>&#8220;Permission Denied&#8221;</b> error if you invoke the script manually from shell. Just type in the following command and chmod db-backup.sh  after logging into shell:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>cPanel-user<span style="color: #000000; font-weight: bold;">/</span>db-backup.sh</pre></div></div>

<p>Now run the script again mamnaully by following :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>cPanel-User<span style="color: #000000; font-weight: bold;">/</span>db-backup.sh</pre></div></div>

<p>And this will definitely create the backup dump.</p>
<p>Hope that helps.</p>
<div style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;;">
										<iframe
											style="height:25px !important; border:none !important; overflow:hidden !important; width:340px !important;" frameborder="0" scrolling="no" allowTransparency="true"
											src="http://www.linksalpha.com/social?link=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fwebmaster-tasks%2Fbackup-your-mysql-databases-automatically-with-cron-job%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/web-hosting/copying-files-from-remote-server-to-another-server-through-ssh/' rel='bookmark' title='Permanent Link: Copying files from remote server to another server through SSH'>Copying files from remote server to another server through SSH</a></li>
<li><a href='http://www.parorrey.com/blog/project-management/ten-step-guide-to-install-redmine-project-management-application/' rel='bookmark' title='Permanent Link: Ten Step Guide to Install Redmine project management application'>Ten Step Guide to Install Redmine project management application</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/webmaster-tasks/backup-your-mysql-databases-automatically-with-cron-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copying files from remote server to another server through SSH</title>
		<link>http://www.parorrey.com/blog/web-hosting/copying-files-from-remote-server-to-another-server-through-ssh/</link>
		<comments>http://www.parorrey.com/blog/web-hosting/copying-files-from-remote-server-to-another-server-through-ssh/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 11:00:28 +0000</pubDate>
		<dc:creator>Ali</dc:creator>
				<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster Tasks]]></category>
		<category><![CDATA[Apache server tricks]]></category>
		<category><![CDATA[SSH commands]]></category>

		<guid isPermaLink="false">http://www.parorrey.com/blog/?p=68</guid>
		<description><![CDATA[For any webmaster, switching web server is a nightmare, especially when there is large number of files to move to a new server. After some bitter experiences, I have found out following methods to move your data files and database quickly and painlessly from one server to another. I’m sure these SSH commands will save [...]


Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/how-to-unzip-files-on-remote-server-using-php-script/' rel='bookmark' title='Permanent Link: how to unzip files on remote server using PHP script'>how to unzip files on remote server using PHP script</a></li>
<li><a href='http://www.parorrey.com/blog/webmaster-tasks/backup-your-mysql-databases-automatically-with-cron-job/' rel='bookmark' title='Permanent Link: Backup your MySQL databases automatically with cron job'>Backup your MySQL databases automatically with cron job</a></li>
<li><a href='http://www.parorrey.com/blog/project-management/ten-step-guide-to-install-redmine-project-management-application/' rel='bookmark' title='Permanent Link: Ten Step Guide to Install Redmine project management application'>Ten Step Guide to Install Redmine project management application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fweb-hosting%2Fcopying-files-from-remote-server-to-another-server-through-ssh%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fweb-hosting%2Fcopying-files-from-remote-server-to-another-server-through-ssh%2F&amp;source=parorrey&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>For any webmaster, switching web server is  a nightmare, especially when there is large number of files to move to a new  server. After some bitter experiences, I have found out following methods to  move your data files and database quickly and painlessly from one server to  another. I’m sure these SSH commands will save your day.</p>
<p>  These methods will copy/get that data files  and database from your old server say <strong>Server  A</strong> to new server say <strong>Server B</strong> without downloading anything to your PC. This way you will save some bandwidth  and valuable time, and lot of anxious moments while your huge files are being  uploaded when after lot of waiting and whining all you see is ‘script timed out’  message.</p>
<p>  I’m assuming here that you have SSH access  to your servers.</p>
<p>  For data files, what I usually do is that I  tar the files because file permissions are preserved and kept intact on the new  server. First login through SSH to the <strong>Server  A </strong>where your files are located. </p>
<p>  Here are the commands: </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>username-of-your-account<span style="color: #000000; font-weight: bold;">/</span>public_html
  <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-cvf</span> backup-website.tar .<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Once it’s done, go to your new server say <strong>Server B</strong> and login through SSH: </p>
<p>  Here are the commands: </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span> username-of-your-account <span style="color: #000000; font-weight: bold;">/</span>public_html
  <span style="color: #c20cb9; font-weight: bold;">wget</span> your-old-domain.com<span style="color: #000000; font-weight: bold;">/</span>backup-website.tar
  <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvf</span> backup-website.tar</pre></div></div>

<p>  That’s it. One caveat here for extraction  of tar file if you are logged in as root user. If you have any cPanel or  HSphere panel available, you should use that to extract the tar file. </p>
<p>  So either log in with your account user  name or If you do extract the tar file with the root user, you probably want to  check and make sure the correct owner and group are on your files you just extracted.  You can check to see what they are by typing: </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span></pre></div></div>

<p>  If the owner or group is wrong you can run  this to change the owner: </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> owner.group .<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>owner.group should be replaced with the  owner name you want and the group name you want. This will recursively go  through all your files and directories and changed them to the correct owner  and group. One warning here, this command can change the owner and group for  all of your files located on new server and can bring down your new server  before even getting started. If the file permissions are not correct, you will  see Forbidden error so only run this command “c<strong>hown“</strong> if you are really sure what you are doing. So be very careful  for this command.</p>
<p>  It would be far better and safer to extract  the tar file using cPanel File Manager or logging in SSH with the hosting account  name.</p>
<p>  Hope that helps.</p>
<p>  Cheers!</p>
<div style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;;">
										<iframe
											style="height:25px !important; border:none !important; overflow:hidden !important; width:340px !important;" frameborder="0" scrolling="no" allowTransparency="true"
											src="http://www.linksalpha.com/social?link=http%3A%2F%2Fwww.parorrey.com%2Fblog%2Fweb-hosting%2Fcopying-files-from-remote-server-to-another-server-through-ssh%2F&fc=333333&fs=arial&fblname=like">
										</iframe>
										</div>

<p>Related posts:<ol><li><a href='http://www.parorrey.com/blog/php-development/how-to-unzip-files-on-remote-server-using-php-script/' rel='bookmark' title='Permanent Link: how to unzip files on remote server using PHP script'>how to unzip files on remote server using PHP script</a></li>
<li><a href='http://www.parorrey.com/blog/webmaster-tasks/backup-your-mysql-databases-automatically-with-cron-job/' rel='bookmark' title='Permanent Link: Backup your MySQL databases automatically with cron job'>Backup your MySQL databases automatically with cron job</a></li>
<li><a href='http://www.parorrey.com/blog/project-management/ten-step-guide-to-install-redmine-project-management-application/' rel='bookmark' title='Permanent Link: Ten Step Guide to Install Redmine project management application'>Ten Step Guide to Install Redmine project management application</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.parorrey.com/blog/web-hosting/copying-files-from-remote-server-to-another-server-through-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
