Cloning Magento website (for staging/dev/uat)

MageStack has a built in feature to be able to clone an existing Magento installation with ease. This can be really useful if you need to create a staging/development site cloned from the latest copy of the LIVE site (including both files and database if necessary).

Using the tool (/microcloud/scripts_ro/clone_store.sh) is really straightforward,

clone_store.sh Usage:

clone_store.sh ([args]) -f [live-path] -t [dev-path]

         -f live-path    Path to directory you are copying FROM (eg. /microcloud/domains/example/domains/example.com/www)
         -t dev-path     Path to directory you are copying TO (eg. /microcloud/domains/example/domains/example.com/dev)

         -r              Restore database in TO destination
         -d              Dump database in FROM destination
         -m              Sync media from FROM to TO
         -n              Verbose dry run (print all commands, but don't run them)

Hooks

  Before and after each action, a script can be executed to help automate translation of data. Use the dry run
  options to preview when the hooks would be run.

Hooks

Before and after each action, a script can be executed to help automate translation of data. Use the dry run options to preview when the hooks would be run and what the path to the specified file would be.

The hooks are taken in the format of a bash script.

Examples

Full clone

Eg. Clone www.example.com to dev.example.com,

  • -m - Including the /media directory
  • -d - Dump the database from the source
  • -r - Restore it in the destination

    /microcloud/scripts_ro/clone_store.sh -f /microcloud/domains/example/domains/example.com/www -t /microcloud/domains/example/domains/example.com/dev -dr -m

If the destination directory does not exist, you'll see the following error,

Error: Path does not exist (/microcloud/domains/example/domains/example.com/dev)

In this case, you just need to make the directory and re-run the command,

mkdir -p /microcloud/domains/example/domains/example.com/dev

Dry run only

If you want to see what commands will be run during the process, before actually running them, you can append a simple -n to the arguments.

Eg. For the example above, clone www.example.com to dev.example.com

/microcloud/scripts_ro/clone_store.sh -f /microcloud/domains/example/domains/example.com/www -t /microcloud/domains/example/domains/example.com/dev -dr -m -n

Which will print the commands that will be executed (but not actually do anything)

cd /microcloud/domains/example/domains/example.com/www
wget -qO mage-dbdump.sh sys.sonassi.com/mage-dbdump.sh
bash mage-dbdump.sh -dF
rsync -vPa /microcloud/domains/example/domains/example.com/www/ /microcloud/domains/example/domains/example.com/dev/ --exclude=/media --exclude=/var/cache --exclude=/var/full_page_cache --exclude=/var/session --exclude=/var/log --exclude=/var/backup --exclude=/var/import --exclude=/var/export --exclude=/var/report --exclude=/var/locks --exclude=/includes/src --exclude=/includes/config.php --delete
cd /microcloud/domains/example/domains/example.com/dev
wget -qO mage-dbdump.sh sys.sonassi.com/mage-dbdump.sh
sed -i s#www.example.com#dev.example.com#g var/db.sql

Files only (no database)

If you want to just sync the files, but not the DB, then you just need to omit the -d and -r options.

Eg. For the example above, clone www.example.com to dev.example.com

/microcloud/scripts_ro/clone_store.sh -f /microcloud/domains/example/domains/example.com/www -t /microcloud/domains/example/domains/example.com/dev -m

Files only (no media)

If you want to just sync the files, but not the DB and media, then you just need to omit the -d, -r and -m options.

Eg. For the example above, clone www.example.com to dev.example.com

/microcloud/scripts_ro/clone_store.sh -f /microcloud/domains/example/domains/example.com/www -t /microcloud/domains/example/domains/example.com/dev