1

We have two magento installation for the same shop. One is named live and the other is named staging.

How can I mirror all products and categories from live with staging?

Do I have to export / import the whole database?

  • do you want same copy as live site into staging, right? or you want just category and product data not other data? – Dhiren Vasoya Sep 7 '18 at 14:26
  • I want categories, products, cms pages, cms blocks etc., basically everything without customers. – Black Sep 7 '18 at 17:51
3

I'd take a look at Magerun's db:dump functionality.

You can run something like n98-magerun.phar db:dump --strip="@development" which will provide a DB dump with customer/order/log data stripped from the SQL export but still include all product/category/core tables.

What I usually run is n98-magerun.phar db:dump --strip="@development" --compression=gzip /tmp/database.sql.gz so it's compressed and then put in /tmp/ to ensure it doesn't go to Magento's public directory.

More information on Magerun's db:dump functionality & installation can be found here (There is also a Magento 2 version here)

*Edit

With this method you will have to update your base URLs and other config once you import the SQL to your staging environment but you can use Magerun to set the config values after the import.

Example:

Create a new admin user staging/password1

n98-magerun.phar admin:user:create staging test@example.com password1 Example User

Amend default base_urls

n98-magerun.phar config:set web/unsecure/base_url http://staging.example.com/
n98-magerun.phar config:set web/secure/base_url http://staging.example.com/
| improve this answer | |
  • But I think this will also delete all admin users. There are many admins and devs working on staging though, do I have to create them again?? – Black Sep 7 '18 at 17:49
  • @Black Actually, admin stripping was added in version 1.100.0 of Magerun. If you download a version below this you won't get this feature. Version 1.99.0 release here - github.com/netz98/n98-magerun/archive/1.99.0.tar.gz – Matt Antley Sep 10 '18 at 9:00
  • is there a way to do this without BE admins getting deleted? I just imported my live db with your instructions to staging, but no one can login to the backend anymore. – Black Sep 10 '18 at 10:58
  • 1
    @Black See my post above your comment. Basically you'll need to delete Magerun on both your staging and production environments and download the 1.99.0 version which can be found here here - github.com/netz98/n98-magerun/archive/1.99.0.tar.gz - This version doesn't include the admin_users table getting stripped on export. Hope that helps! – Matt Antley Sep 10 '18 at 11:06
  • I just tried it, but the admin_users table is still getting stripped... – Black Sep 10 '18 at 11:24
1

According to your requirement you need to do this things.

  1. Copy the database from live to staging.

  2. Create one script in magento root with this code. (Ex : test.php)

    <?php
    $mageFilename = 'app/Mage.php';
    if (!file_exists($mageFilename)) {
              echo $mageFilename." was not found";
    exit;
    }
    require_once $mageFilename;
    Mage::app();
    Mage::register('isSecureArea', true);
    try 
    {
    
        $customers = Mage::getModel("customer/customer")->getCollection();
    
        foreach ($customers as $customer) {
             $customer->delete();
        }
        echo "Customer Delete Sucessfully";
    } catch (Exception $e) {
       echo $e->getMessage();
    
    }
    ?>
    
  3. Now run this file from browser. (Ex : www.domain.com/test.php)

| improve this answer | |
  • Is it not possible to just import the categories, products and cms pages? Do I really have to import the whole database? – Black Sep 8 '18 at 19:16
  • Then you need to find or create custom solution to import only those data. But easy way I already specify above. – Dhiren Vasoya Sep 9 '18 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.