<?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>SiteValley Web Hosting Blog&#187; Cronjob</title>
	<atom:link href="http://svhostingblog.com/tag/cronjob/feed/" rel="self" type="application/rss+xml" />
	<link>http://svhostingblog.com</link>
	<description>Ecommerce Web Hosting, Web Development, Promotions, News &#38; Trends of the Industry</description>
	<lastBuildDate>Fri, 24 Jun 2011 19:18:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Simple, yet powerful WordPress backup script. Cron job setup howto.</title>
		<link>http://svhostingblog.com/guides/simple-yet-powerful-wordpress-backup-script-cron-job-setup-howto/</link>
		<comments>http://svhostingblog.com/guides/simple-yet-powerful-wordpress-backup-script-cron-job-setup-howto/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 16:16:40 +0000</pubDate>
		<dc:creator>Smirnovi4</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Automated backup]]></category>
		<category><![CDATA[Backup script]]></category>
		<category><![CDATA[Cronjob]]></category>
		<category><![CDATA[database dump]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://svhostingblog.com/?p=397</guid>
		<description><![CDATA[TweetBackups as precautions against data loss. Every hosting account holder must understand the importance of backups. They play the same role in information technology, a car insurance plays in everyday life. Backups help you in case of unexpected issues with content on your account. Forums, blogs and similar projects take a lot of time to [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://svhostingblog.com/guides/simple-yet-powerful-wordpress-backup-script-cron-job-setup-howto/&via=sitevalley&text=Simple, yet powerful WordPress backup script. Cron job setup howto.&related=:&lang=en&count=vertical" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><h2 style="text-align: justify;"><span style="color: #000000;">Backups as precautions against data loss.</span></h2>
<p>Every hosting account holder must understand the importance of backups. They play the same role in information technology, a car insurance plays in everyday life. Backups help you in case of unexpected issues with content on your account. Forums, blogs and similar projects take a lot of time to develop, but one serious spontaneous error in the system can damage all your information or even make it vanish entirely. This can happen due to numerous reasons: hardware and software faults, to name a few. Take into consideration such widely spread activity as hacking, and you will realize the scale of existing menaces. As a matter of fact, any WordPress blog, which is not updated on time, can easily fall victim to such malicious activity . This is also true for any kind of web software. Last but not least, you can accidentally <span style="color: #000000;">make errors in</span> data of your blog yourself, and then you need a point to roll back to. Backups <span style="color: #000000;">enable you to do just that.</span></p>
<p style="text-align: justify;">One of the easiest ways to make sure you can recover after most content related disasters is to make backups of your account from time to time. In case you run a WordPress based blog, having a backup of entire account is not necessary. It is enough to simply have a couple of healthy database dumps, which contain all important information, including your posts. Since posts are the most important part of any blog, having them in reserve archives saves you a lot of work in case of emergency restoration.</p>
<h2 style="text-align: justify;"><span id="more-397"></span>MySQL database backup script</h2>
<p style="text-align: justify;">There are numerous backup plugins for WordPress, but the mechanisms used in them are not as secure and reliable as the method described below. I will try to explain a way to use cron jobs on your hosting account to perform back up of your WordPress database.</p>
<p style="text-align: justify;">The cron is a special scheduling service independently run on the server. Let’s say we have a set of commands to be executed. In this case, using cron jobs<span style="color: #000000;"> commands can be scheduled for regular execution</span>, requiring no attention from the user whatsoever. The process will be fully automated. Since cron is an independent service, it is more reliable and more efficient than the wordpress plugin scripts. There is a special section for configuring crons with the help of GUI in most hosting control panels.</p>
<p style="text-align: justify;">The set of commands we want to be executed in the framework of backup procedure is relatively small. <span style="color: #000000;">First of all, backup dump creation will be scheduled and compressed immediately after being made in order to conserve disk space. </span>We will also apply the command to change the access permissions for this archive in order to decrease the possibility of it being stolen or damaged. We can configure backup to be written to the same file on the daily basis (the simplest solution), but this is not very <span style="color: #000000;">convenient</span>, as corruption of information can happen without you noticing it and then this corruption will be written over a healthy backup. We will make backups on the daily basis, but will write the information into different files. The date will be added to the name of the file, so that it is easier to identify files you need. Additionally, we will configure the cron to delete the backup files, which are over 7 days old, in order not to fill up the space on the account with backups.</p>
<p style="text-align: justify;">The list of described commands needs to be stored in one file. This allows us to use just one task in cron daemon to execute several described commands. Files of this kind are called scripts. I will show what the content of the file can be on example of commands used on Sitevalley <a href="http://www.sitevalley.com/blog-hosting/">Blog hosting</a> account. (Please note that some paths can differ for various operating systems, such as FreeBSD and Linux. The list of commands given here is for usage in FreeBSD OS installed on Sitevalley hosting servers. If you are not sure about correct paths/locations, it is better to consult your hosting administrators).</p>
<p style="text-align: justify;">You can use any text editor to create the script file. It needs to have extension ‘.sh’. I named the file ‘wp-bps.sh’. The content of the script file should be the following (Please note: I take no responsibility for any data loss or corruption when using this script):</p>
<p><em>#!/bin/sh</em> <span style="color: #0000ff;">#This line shows the cron what utility should be used to execute the commands in this file.</span></p>
<p><span style="color: #0000ff;"><em> </em></span></p>
<p><span style="color: #0000ff;"><em># Username to access the MySQL server. In the line below substitute the ‘database_user_name’<br />
#with the appropriate username for the database of your wordpress.</em></span></p>
<p><em>USERNAME=database_user_name</em></p>
<p><em> </em></p>
<p><span style="color: #0000ff;"><em># Username to access the MySQL server. In the line below substitute the ‘database_password’<br />
#with the appropriate password for the database of your wordpress.</em></span></p>
<p><em>PASSWORD=database_password</em></p>
<p><em> </em></p>
<p><span style="color: #0000ff;"><em># Host name (or IP address) of MySQL server. Here simply leave the ‘localhost’.</em></span></p>
<p><em>DBHOST=localhost</em></p>
<p><em> </em></p>
<p><span style="color: #0000ff;"><em># Name of the database to make the backup of. In the line below substitute the ‘database_name’<br />
#with the appropriate name of your wordpress database.</em></span></p>
<p><em>DBNAME=database_name</em></p>
<p><em> </em></p>
<p><span style="color: #0000ff;"><em># Backup directory location. In the line below substitute the ‘backup_directory’<br />
#with the path to the directory where you want your backups stored.</em></span></p>
<p><span style="color: #0000ff;"><em>#E.g. /usr/home/username/domains/myblog.com/public_html/wp-backups/</em></span></p>
<p><em>BACKUPDIR=&#8221;backup_directory&#8221;</em></p>
<p><em> </em></p>
<p><span style="color: #0000ff;"><em>#Specify the age of the backups that should be deleted.</em></span></p>
<p><span style="color: #0000ff;"><em>#This is needed in order to avoid abusing the space on account with backups.</em></span></p>
<p><span style="color: #0000ff;"><em>#(m=month; h=hours, m=minutes, s=seconds).</em></span></p>
<p><span style="color: #0000ff;"><em>#Substitute the ‘backup_age’ with an appropriate value (e.g. 7d).</em></span></p>
<p><em>BPAGE=backup_age</em></p>
<p><em> </em></p>
<p><span style="color: #0000ff;"><em>#Location of mysqldump command. Here you need to substitute the ‘path_to_mysqldump’<br />
#with the path to the location where the mysqldump command is situated.</em></span></p>
<p><span style="color: #0000ff;"><em>#E.g. /usr/local/mysql-5.0.51a-freebsd7.0-i386/bin/</em></span></p>
<p><em>MYSQLDUMPLOC=&#8221;path_to_mysqldump&#8221;</em></p>
<p><em> </em></p>
<p><span style="color: #ff6600;"><em>#No changes needed below this line</em></span></p>
<p><em>PATH=$PATH:$MYSQLDUMPLOC;</em></p>
<p><em>DATE=`date +%Y-%m-%d_%Hh%Mm`</em></p>
<p><em>mysqldump -u$USERNAME -p$PASSWORD $DBNAME | gzip &gt; $BACKUPDIR/mysql_backup_$DATE.gz;</em></p>
<p><em>chmod 600 $BACKUPDIR/mysql_backup_$DATE.gz;</em></p>
<p><em>find $BACKUPDIR -type f -name &#8220;*.gz&#8221; -mtime +$BPAGE -exec rm -f {} \;</em></p>
<p style="text-align: justify;">You need to make changes described on lines in blue color (you can download a file with this script <a title="Wordpress-backup-script-tamplate" href="http://svhostingblog.com/wp-content/uploads/2009/12/wp-bps-template.txt" target="_blank">here</a>). If you are not sure about <em>database_user_name, database_password </em>and<em> database_name </em>you can check this information in the file ‘wp-config.php’ located in the folder where you installed your wordpress. You need to look for the following lines within this file (information in blue in the example):</p>
<p><sup>// ** MySQL settings &#8211; You can get this info from your web host ** //</sup></p>
<p><sup>/** The name of the database for WordPress */</sup></p>
<p><sup>define(&#8216;DB_NAME&#8217;, &#8216;<span style="color: #0000ff;">your database name here</span>&#8216;);</sup></p>
<p><sup>/** MySQL database username */</sup></p>
<p><sup>define(&#8216;DB_USER&#8217;, &#8216; <span style="color: #0000ff;">your database user here</span> &#8216;);</sup></p>
<p><sup>/** MySQL database password */</sup></p>
<p><sup>define(&#8216;DB_PASSWORD&#8217;, &#8216; <span style="color: #0000ff;">your database password here</span> &#8216;);</sup></p>
<p><sup>/** MySQL hostname */</sup></p>
<p><sup>define(&#8216;DB_HOST&#8217;, &#8216;<span style="color: #0000ff;"> your MySQL hostname here</span> &#8216;);</sup></p>
<p style="text-align: justify;">When you are done editing your .sh file, you need to upload it to your hosting account. As soon as it is done, change its permissions to 600. This permission set <span style="color: #000000;"> </span><span style="color: #00ff00;"><span style="color: #000000;">will prevent other users on the server and your site visitors from accessing and editing</span></span> this file, which is a reasonable security measure.</p>
<p style="text-align: justify;">Now your script file is completely ready to be used with a cron. Go to your Direct Admin control panel (or any other admin panel). Follow the steps shown in figure 1 and 2 to configure the cron job (figures are applicable to DirectAdmin panel only).</p>
<p style="text-align: center;">
<div id="attachment_402" class="wp-caption aligncenter" style="width: 283px"><a href="http://svhostingblog.com/wp-content/uploads/2009/12/Location_of_cronjob_menu_in_Direct_admin.png"><img class="size-medium wp-image-402" title="Cron Job menu in DerectAdmin" src="http://svhostingblog.com/wp-content/uploads/2009/12/Location_of_cronjob_menu_in_Direct_admin-273x300.png" alt="Cron Job menu button in DA" width="273" height="300" /></a><p class="wp-caption-text">Cron menu location in DA</p></div>
<p style="text-align: center;">Figure 1. Cronjobs menu</p>
<p style="text-align: center;">
<div id="attachment_404" class="wp-caption aligncenter" style="width: 310px"><a href="http://svhostingblog.com/wp-content/uploads/2009/12/Configuring_cronjob1.png"><img class="size-medium wp-image-404" title="Cron configuration tips" src="http://svhostingblog.com/wp-content/uploads/2009/12/Configuring_cronjob1-300x178.png" alt="Description of parameters in Cronjob menu in DA" width="300" height="178" /></a><p class="wp-caption-text">Description of parameters in Cronjob menu in DA</p></div>
<p>This is it,<span style="color: #00ff00;"> <span style="color: #000000;">the cron job has been scheduled to regularly execute the backup script</span></span><span style="color: #000000;">.</span> You can download the backup files to your local PC or Mac using a regular FTP or SCP client. Even though the cron will work autonomously, it is still recommended to occasionally download copies to your local computer. I recommend doing this because we have configured the script to delete the backups which are over 7 days old.</p>
<h2>Conclusions</h2>
<p>Using cronjobs for backing up your wordpress databases is relatively easy, yet very reliable. Such backup script posses several advantages as compared to plugins, such as:</p>
<ul>
<li>The backups are performed under control of      cron daemon, which is independent from WordPress or any other script.</li>
<li>Such backing up approach can be used for      any software, not only WordPress.</li>
<li>The backup operation is done on behalf of a      user. This allows applying strict restrictions on the access permissions      for the backed up data (e.g. 600), thus securing the important content as      well as login details.</li>
</ul>
<p>Of course setting up such cronjob requires a little typing and research. But in general, it is easy enough for any beginner to implement. And unlike plugins the code is very clear and easy to understand and debug in case of issues.</p>
<p>We at Sitevalley hope this code will help making your hosting experience safer and more efficient.</p>
]]></content:encoded>
			<wfw:commentRss>http://svhostingblog.com/guides/simple-yet-powerful-wordpress-backup-script-cron-job-setup-howto/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

