<?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>NemoPS &#187; backup</title>
	<atom:link href="http://nemops.com/tag/backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Creating Cron Jobs for PrestaShop Backups</title>
		<link>http://nemops.com/prestashop-backups-cron-jobs/</link>
		<comments>http://nemops.com/prestashop-backups-cron-jobs/#comments</comments>
		<pubDate>Tue, 28 Jun 2016 09:32:05 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[prestashop]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2804</guid>
		<description><![CDATA[<p>Having regular backups is the very first important thing to consider, whenever you have a running web-shop. In this tutorial, we will see how to automate PrestaShop Backups using a simple script and a cron job. The backup script PrestaShop has a very simple way to create backups. In the back office controller, once you [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-backups-cron-jobs/">Creating Cron Jobs for PrestaShop Backups</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Having regular backups is the very first important thing to consider, whenever you have a running web-shop. In this tutorial, we will see how to automate PrestaShop Backups using a simple script and a cron job.</p>
<p><span id="more-2804"></span></p>
<h2>The backup script</h2>
<p>PrestaShop has a very simple way to create backups. In the back office controller, once you hit the button to create a new one, it will simply call the <strong>add()</strong> method on the <strong>PrestaShopBackup</strong> object instance.<br />
We can take advantage of this simplicity to create our own script, that can be called at any time to create a new backup.<br />
To keep things simple, let&#8217;s use the root folder of our shop. Inside it, create a new file named <strong>back-me-up.php</strong>. We will later create a cron job using cPanel to target this very script.<br />
Open it up, and start by including the following in php tags:</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
</pre>
<p>This part initializes PrestaShop, and let&#8217;s us use its classes and functions.<br />
It is essential to create at least a bare minimum level of security, as it would be really unpleasant for us to find out HDD space filled up because someone executed our backup script dozens of time repetitively.</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

$key = 'mypassword';

if(!Tools::getValue('k') || Tools::getValue('k') != $key)
	die('unauthorized');

</pre>
<p>We are almost done. At this point, we need to define the admin folder constant, in case it&#8217;s not been defined. This is needed for the backup script to run, otherwise it will simply die.</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

$key = 'mypassword';

if(!Tools::getValue('k') || Tools::getValue('k') != $key)
	die('unauthorized');

if(!defined('_PS_ADMIN_DIR_'))
	define('_PS_ADMIN_DIR_',  getcwd().'/nameofmyadmin');
</pre>
<p>Make sure you replace the nameofmyadmin string with the name of your own admin folder.<br />
Lastly, let&#8217;s run the backup itself:</p>
<pre class="brush: php; title: ; notranslate">
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

$key = 'mypassword';

if(!Tools::getValue('k') || Tools::getValue('k') != $key)
	die('unauthorized');

if(!defined('_PS_ADMIN_DIR_'))
	define('_PS_ADMIN_DIR_',  getcwd().'/nameofmyadmin');

$backup = new PrestaShopBackup();
if($backup-&gt;add())
	die('success');
else die('error');
</pre>
<p>We are done with php! We just need to create a cron job that runs our script.<br />
Before that, I strongly recommend to manually check if it works, by reaching your site&#8217;s url /back-me-up.php?k=mypassword</p>
<div class="separator"></div>
<h2>Target our new file with a cron job</h2>
<p>You can skip this part if you already know how to create a cron job. If not, read on. I am using cPanel for the example, so if you have another control panel for your hosting space, you might have to find your way through the cron jobs setup screen.</p>
<p>Access your hosting&#8217;s cpanel, and navigate to Cron Jobs</p>
<p><a href="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups1.png"><img src="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups1.png" alt="Setting up Cron Jobs in PrestaShop 1" width="510" height="483" class="aligncenter size-full wp-image-2807" /></a></p>
<p>For the example, create a new cron job that runs every minute (you can choose it from the common settings)</p>
<p><a href="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups2.png"><img src="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups2-680x436.png" alt="PrestaShop Backup cron job settings" width="680" height="436" class="aligncenter size-large wp-image-2808" /></a></p>
<p>If you are new to cron jobs, you might have some trouble finding out the correct url. What we need to do here, in the cron command, is executing php on our script, adding the k parameter as well. Here is how the command is supposed to look like</p>
<pre class="brush: php; title: ; notranslate">
php /home/nameofyouraccount/public_html/path/to/your/main/folder/back-me-up.php k=mypassword
</pre>
<p>The account name is usually the cPanel login. If not, you can read it on the left side of the cPanel homepage, being part of <strong>Home Directory</strong></p>
<p><a href="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups3.png"><img src="http://nemops.com/wp-content/uploads/2016/06/cronjobs_for_backups3.png" alt="Find your account name in cPanel" width="377" height="324" class="aligncenter size-full wp-image-2809" /></a></p>
<p>Unlike with a direct url execution, when you pass in any query string parameter, they must not be preceded by a question mark, not separated by amperstands; they can simply be added one by one, separated by spaces, after the url<br />
If your site is in the root folder (public_html), the url will be</p>
<pre class="brush: php; title: ; notranslate">
php /home/nameofyouraccount/public_html/back-me-up.php k=mypassword
</pre>
<p>Save it, then go back to your PrestaShop admin, and reach <strong>Advanced Parameters > DB Backup</strong>. Wait a couple of minutes, then refresh the page. You should see a few new backup files (depending on the size of your shop, it might take a bit). If you do not, and your shop is relatively small, you might want to check the cron url is correct. It might take several minutes to back up your site, if you have more than a couple of hundreds of products.</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-backups-cron-jobs/">Creating Cron Jobs for PrestaShop Backups</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-backups-cron-jobs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
