linux — how to exclude directory or files when bakup with rsync

rsync has been heavily used in server daily backup.I am not going to list all option of rsync. i just don’t want to backup some useless file such as cache and log file.

In a typical backup situation, you might want to exclude one or more files (or directories) from the backup. You might also want to exclude a specific file type from rsync.

To exclude a special directory,take a look at the command below:

[codesyntax lang=”bash”]

rsync -avze 'ssh -p7788' --exclude 'dir_abc'  /home/www  root@ip:/home/bak/


This command will not sync the /home/www/dir_abc

You can use * to match multiple directory to exclude like this:

[codesyntax lang=”bash”]

rsync -avze 'ssh -p7788' --exclude 'dir_*'  /home/www  root@ip:/home/bak/


You can also use multiple –exclude option to exclude:

[codesyntax lang=”php”]

rsync -avze 'ssh -p7788' --exclude 'dir_abc' --exclude 'webcache' --exclude '*.log' /home/www  root@ip:/home/bak/


Keep in mind that rsync will always treat the value of the –exclude option as relative to the bakup dir even though you specified a absolute path,so

if there is a dir1 directory in /home/www

[codesyntax lang=”bash”]

rsync -avze --exclude '/home/www/dir1' /home/www /home/bak


rsync will explain /home/www/dir1 as /home/www/home/www/dir1,but this is not what you want.when you specified the path for –exclude option,make sure it’s relative to the source data diretory.this action will not be affected by add / to the exclude path.

zen cart — Basic search engine optimisation guide for zen cart

Meta tag optimisation

It’s important that meta tag tile and meta tag description contain enough search information for the search engine to index each product effectively,whilst also enticing browser to visit your site.

The meta tag tile and meta tag description are set up to automatically to show product name and descrition when you setting up product to your zen cart store.You can further enhance these tags for specific categories and products by clicking on ‘Meta Tags defined’ button in the catalog listing page within zen cart.

It’s normally advisalbe to show the product name,category and manufacturer in the Meta tag Title.The meta tag description should contain the product name and it’s main features.

product name optimisation

It’s important to include keywords in the product and category name.For example, a product with name ’30 x 78 mm (xyz666)  1 ply Till Roll’ will gain more search engine score than a name with ’30 x 78 mm (xyz666)’ without keywords.

product description optimisation

It’s beneficial to list keywords associated with a product in product description. This can be further enhanced by making the products keywords bold.or even more,you can consider randomly insert variant forms of the product keywords to the product descrption.

magento — how to check product page or category page?

you may need to do some specific work when magento are in product page,and not show some content in category list to check ?

// if this is a product view page
if (Mage::registry(‘product’)) {
// get collection of categories this product is associated with
$categories = Mage::registry(‘product’)->getCategoryCollection()
->setPage(1, 1)

from the last block code from magento, when Mage::registry(‘product’) is not null,magento are work in product view page.

if (!$this->_currentCategoryKey) {
$category = Mage::registry(‘current_category’);
if ($category) {
$this->_currentCategoryKey = $category->getPath();

obviously, if Mage::registry(‘current_category’) is set and not null,then we are in category page.but,this not work in all version of magento.we can extend magento in its core to set some status variable for test.Mage::registry will be a good way to do this job.


How to override a Magento function

How to override a Global Magento function which was defined in app/code/core/Mage/Core/functions.php? With the help of magento override system,we can easily ovrride any global function defined in the function.php by make a copy of this file to app/code/local/Mage/Core/ the new file,do whatever changes you want.when magento call a function,it will use the definition in the new file.Kee in mind that code in the local code pool always takes precedence over that in the core pool.this is the way magento works always.

read more from:

magento – Magento Service Temporarily Unavailable

If your magento website got this error page,

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

don’t be too worried!First,make sure you don’t put your magento store in maintenance mode.If Magento sees a file named maintenance.flag in the magento store root directory, it will automatically redirect all requests to the magento default 503 error page. This can be used  to prevent users from accessing the store during magento upgrades. To revert your magento store back to production mode,just delete/rename the maintenance.flag file.

However, this error page may also be caused by magento upgrade. If you tried to install magento theme/template/module,magento would temporally put magento store in maintenance mode if it needs to upgrade magento. if the upgrade didn’t finish successfully,it won’t revert the magento store back to production mode.If so,you only need to remove the maintenance.flag to get control back to magento backend. Remove the extension/plugins you installed,it will be ok.


magento – how to rewrite a model class to extend magento feature

To add  or extend magento core feature, we need to make changes to magento code.however,we would not want to change the code directly.To make our code be compatible with magento next release,we’d better make use of magento build in way to extend magento functionality.

To rewrite a magento existing core model,we have two choice.The first one is based upon php include path.Let’s take a look at magento code:

if (defined(‘COMPILER_INCLUDE_PATH’)) {
set_include_path($appPath . PS . Mage::registry(‘original_include_path’));
include_once “Mage_Core_functions.php”;
include_once “Varien_Autoload.php”;
} else {
* Set include path
$paths[] = BP . DS . ‘app’ . DS . ‘code’ . DS . ‘local’;
$paths[] = BP . DS . ‘app’ . DS . ‘code’ . DS . ‘community’;
$paths[] = BP . DS . ‘app’ . DS . ‘code’ . DS . ‘core’;
$paths[] = BP . DS . ‘lib’;

$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry(‘original_include_path’));
include_once “Mage/Core/functions.php”;
include_once “Varien/Autoload.php”;

with the include_path configuration set,magento will search first at the local code pool,then community and core code we can just copy the file which contain the class you want to change from the core code pool to local code pool,and do whatever changes you want.For example,to rewrite the product model class,just copy core/Mage/Catalog/Model/Product.php to local/Mage/Catalog/Model/Product.php.Although the changes we made would keep when we update magento, we still lost the new updated/added feature.

magento has another powerful way to change its core code.this is magento another override mechanism.let’s take a look how it works.

when we try to get a model instance,we call Mage:getModel ,ie $p = Mage:getModel(‘catalog/product’); The real logic is implemented in the getGroupedClassName method of Mage_Core_Model_Config class defined in app\code\core\Mage\Core\Model\Config.php

public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
if (empty($groupRootNode)) {
$groupRootNode = ‘global/’.$groupType.’s’;

$classArr = explode(‘/’, trim($classId));
$group = $classArr[0];
$class = !empty($classArr[1]) ? $classArr[1] : null;

if (isset($this->_classNameCache[$groupRootNode][$group][$class])) {
return $this->_classNameCache[$groupRootNode][$group][$class];

$config = $this->_xml->global->{$groupType.’s’}->{$group};

// First – check maybe the entity class was rewritten
$className = null;
if (isset($config->rewrite->$class)) {
$className = (string)$config->rewrite->$class;
} else {
* Backwards compatibility for pre-MMDB extensions.
* In MMDB release resource nodes <…_mysql4> were renamed to <…_resource>. So <deprecatedNode> is left
* to keep name of previously used nodes, that still may be used by non-updated extensions.
if ($config->deprecatedNode) {
$deprecatedNode = $config->deprecatedNode;
$configOld = $this->_xml->global->{$groupType.’s’}->$deprecatedNode;
if (isset($configOld->rewrite->$class)) {
$className = (string) $configOld->rewrite->$class;

// Second – if entity is not rewritten then use class prefix to form class name
if (empty($className)) {
if (!empty($config)) {
$className = $config->getClassName();
if (empty($className)) {
$className = ‘mage_’.$group.’_’.$groupType;
if (!empty($class)) {
$className .= ‘_’.$class;
$className = uc_words($className);

$this->_classNameCache[$groupRootNode][$group][$class] = $className;
return $className;

so to rewrite a model class,we just need to add proper xml config and extend the orginal model class in the new class of your own namespace in the local code pool,so to rewrite product model,

first,set xml as below:

then declare the new class to textend the original only will this class be compatible with next magento release,but also it would have any new/updated feature  of product model,because the new class extends the original class.
class Mzcart_Catalog_Model_Product extends Mage_Catalog_Model_Product {
  //do whatever changes you want
both the above  methods can be used to to rewrite any magento helper class,block class.

magento — Fatal error: Call to undefined method Mage_Core_Helper_Data::quoteEscape()

one of my customer get this error in the magento admin backend when he install some extension.At last i found this was caused by unfinished upgrade of magento core module.of course,the update was executed when he installed the extension.

his original magento version is magento, i guess it’s been updated to 1.7 but not finished due to some i upload the Mage/Core/Helper/Abstract.php to override and fixed the error.

magento — magento update failed lead to Fatal error: Class ‘Mage_Core_Helper_Hint’ not found

one of my customer ask me to help to fix his prob.he tried to updated magento 1.6.2 to magento 1.7. After that,he logged into the magento backend,and got the following error:

Fatal error: Class ‘Mage_Core_Helper_Hint’ not found

it was obviously that the update process was interrupted due to some problem,Mage_Core_Helper_Hint class was added on mag1.7,just upload the file(Mage/Core/Helper/Hint) that defined the class and the error get fixed.but we may need to check if there are some other missing file.

zen cart — simple script to limit access to zen cart backend to special ip(s)

The script is to limit the access to the specifed ips.

* limit zen cart admin backend only available to specified ips
* @author george zheng <>
* @date 09/05/2012

if ($_SERVER[‘REMOTE_ADDR’] != $ip) {
die(‘You are not permitted to admin backend’);

if (count($ips) && !in_array($_SERVER[‘REMOTE_ADDR’],$ips)) {
die(‘You are not permitted to admin backend’);

zen cart — clear weird char from url of product and cateogry page

with the help of ‘Ultimate SEO URLs’ module,zen cart can generate search engine friendly urls. Though this module do have a feature to replace specified char in the generated url, nobody can set all weird character one by one. it may take a lot time. below is a patch to the ‘Ultimate SEO URLs’ module,which will clear all none ASCII char.

edit the inlcudes/classes/seo.url.php file, add the following line to the function stock_href_link before the switch block:

//fix by george to remove weird char
$link = preg_replace(‘/[^(\x20−\x7F)\x0A]*/’,”, $link);
//end of george fix