<?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>Joe's Linux Blog &#187; web</title>
	<atom:link href="http://joseph.freivald.com/linux/tag/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://joseph.freivald.com/linux</link>
	<description>Linux Admin tips and tricks</description>
	<lastBuildDate>Sat, 31 Dec 2011 07:36:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using rsync to update a website on hostmonster.com</title>
		<link>http://joseph.freivald.com/linux/2009/06/05/using-rsync-to-update-a-website-on-hostmonstercom/</link>
		<comments>http://joseph.freivald.com/linux/2009/06/05/using-rsync-to-update-a-website-on-hostmonstercom/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 03:32:10 +0000</pubDate>
		<dc:creator>jfreivald</dc:creator>
				<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Web Publishing]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://joseph.freivald.com/linux/?p=29</guid>
		<description><![CDATA[I was working on a website with a software repository that had hard links in it. Linking reduces disk space on the server, and when mirroring with rsync, reduces the time needed to sync the entire mirror.  If you are using scp or ftp to push to the server it causes problems because those programs [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a website with a software repository that had hard links in it.  Linking reduces disk space on the server, and when mirroring with rsync, reduces the time needed to sync the entire mirror.  If you are using scp or ftp to push to the server it causes problems because those programs copy each link as a new file, meaning more bandwidth consumed, more time in transfer, and more disk space used on the server side.  Just what we wanted to avoid by using rsync in the first place.</p>
<p>So how do we use rsync to push our web site to the server when we don&#8217;t have access to any of the rsyncd configuration files and can&#8217;t work with anything higher in the file tree than our home directory?  Sure we could pay more for a dedicated server, but why?  Lets use the tools we have as a simple user to accomplish what we need cheaply and easily.</p>
<p>First, get ssh access for your host server.  Hostmonster requires a faxed copy of a picture ID and some other confirmation.  Whatever your host requires, follow their procedures.</p>
<p>Test your ssh connection by opening a terminal and typing:</p>
<pre>ssh <em>username</em>@<em>hostname</em></pre>
<p>It will ask you if you want to remember the host key and you should respond with a yes.</p>
<p>If you are able to enter your password and log in, you should be at your home directory on the host server. You should be able to see the files for your website with</p>
<pre>ls ~/public_html</pre>
<p>Type the following commands:</p>
<pre>mkdir ~/.ssh
chmod 700 ~/.ssh</pre>
<p>Log out and return to your local computer&#8217;s prompt and enter the following commands:</p>
<pre>ssh-keygen -t dsa -C <em>youremailaddress</em></pre>
<p>ssh-keygen will ask you some questions.  Using the default file name (/home/<em>username</em>/.ssh/id_dsa) is fine.  It will also prompt you for a password.  This will guard your ssh key, and you only have to type it once per session, so make it a good one.</p>
<p>Once complete, you should have two new files in ~/.ssh: id_dsa and id_dsa.pub.    Create a configuration shortcut:</p>
<pre>echo -e "host <em>shortname</em>\n\tHostName <em>hostname</em>\n\tUser <em>username</em>" &gt;&gt; ~/.ssh/config</pre>
<p>Where <em>shortname</em> is any name that you want to use to represent your website, <em>hostname</em> is the host that you are uploading to, and <em>username</em> is your login name on that server.</p>
<p>Now, send the public key to the server with:</p>
<pre>scp ~/.ssh/id_dsa.pub <em>username</em>@<em>hostname</em>:~/.ssh/authorized_keys2</pre>
<p>Now, to prevent yourself from having to type your password every time you want to copy files or log in, type:</p>
<pre>ssh-add</pre>
<p>and type your password.  This will put your ssh key into an &#8216;agent&#8217;, which will authorize you without a password for the rest of the time you are logged in.  After you log out you&#8217;ll have to do ssh-add again, but as long as you stay logged in you should be able to log into the hosting server with a simple:</p>
<pre>ssh <em>shortname</em></pre>
<p>No password, no nothing, and all encrypted, too.  Log out of the server and get back to a local prompt.</p>
<p>Change to your directory that has the local copy of your web site, such as:</p>
<pre>cd ~/public_html</pre>
<p>To push the update your web site, type the command is:</p>
<pre>rsync -e ssh -vramlHP --exclude '*.log' --numeric-ids --delete --delete-excluded --delete-after --delay-updates . <em>shortname</em>:~/public_html/</pre>
<p>To pull the webserver down to your local directory, the command is:</p>
<pre>rsync -e ssh -vralmHP --exclude '*.log' --numeric-ids --delete --delete-excluded --delete-after --delay-updates <em>shortname</em>:~/public_html/ .</pre>
<p>It will transmit only the changed data, saving you time, and will properly handle hard and soft links, which will save you space on the server.</p>
<p>Just to finish the job I put them into shell scripts by:</p>
<pre>mkdir ~/bin
echo -e '#!/bin/bash\n\nrsync -e ssh -vralHP --numeric-ids --delete --delete-excluded --delete-after --delay-updates <em>localdirectory</em> <em>shortname</em>:~/public_html/\n' &gt;&gt; ~/bin/pushsite
echo -e '#!/bin/bash\n\nrsync -e ssh -vralHP --numeric-ids --delete --delete-excluded --delete-after --delay-updates <em>shortname</em>:~/public_html/ <em>localdirectory</em>\n' &gt;&gt; ~/bin/pullsite
chmod +x ~/bin/pushsite ~/bin/pullsite</pre>
<p>Where <em>localdirectory</em> is where you want the site stored locally.</p>
<p>Now typing &#8216;pushsite&#8217; at a terminal prompt will push the update, and &#8216;pullsite&#8217; will pull it down from the server (assuming your local bin dir is in your path, which it is on most systems).  Assuming you have previously done an &#8216;ssh-add&#8217;, you won&#8217;t even need to use a password.</p>
<p>Of course, this doesn&#8217;t backup databases, just static files.  But if you are dealing with static files, rsync can&#8217;t be beat.  It will push and pull only the changes, and will properly handle hard and soft links without duplicating the files.</p>
<p>Happy publishing.</p>
]]></content:encoded>
			<wfw:commentRss>http://joseph.freivald.com/linux/2009/06/05/using-rsync-to-update-a-website-on-hostmonstercom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

