As the oficial n98-magerun repo on GitHub says:
The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.
At Magently we couldn’t agree more. Magerun is the tool for Magento development. In this article we will talk you through some of the most useful commands.
Cache
Many problems in Magento can be solved by clearing cache. To do so, you usually have to log in to Magento panel and go to System > Cache Management > Flush Magento Cache. However, that’s simply too much clicking for a savvy Magento dev. What can you do instead?
$ n98-magerun.phar cache:flush
Tip: It is handy to keep a terminal window open all time when working with Magento.
(Re-)index
The problems that can’t be solved by clearing cache can be often fixed with re-indexing. „Did you try clearing cache and reindexing?” is the new „Did you try turning it off and on again?”. Don’t fancy clicking through the panel? There you go:
$ n98-magerun.phar index:reindex:all
You’re welcome.
Cron
Sooner or later every Magento developer has to deal with cron jobs. Sooner or later something isn’t going to work. What then? Modify the code, wait for the next scheduled run and check the results? Certainly not. First remember to check if the job is executed at all:
$ n98-magerun.phar sys:cron:history
Then, run it manually:
$ n98-magerun.phar sys:cron:run
Modify it and run it again. And again. And possibly again… Until it works.
Admin
Your client has given you a database dump without the password to the panel? You need to access the panel, but your client doesn’t want you to fiddle with the production site? Not sure what to do?
Either:
$ n98-magerun.phar admin:user:create [username] [email] [password] [firstname] [lastname] [role]
or:
$ n98-magerun.phar admin:user:change-password [username] [password]
This will give you a full access to the panel on your server and your client won’t be concerned about their shop.
Database
Sometimes, when working simultaneously on a development server, client server, locally and possibly on few other installations, you’ll need to dump the database in one place and upload it to a different one. If in your case ‘sometimes’ means a dozen times or so during the day and you’re doing it via phpMyAdmin, you will end up spending 60 % of your time every day waiting for the database to be updated. Provided that your phpMyAdmin is able to import a 200 MB dump. And even if it is, your client’s most likely isn’t.
In this situation
$ n98-magerun.phar db:dump [filename]
and
$ n98-magerun.phar db:import [filename]
become your best mates. Also, you usually don’t need sales and customer data when launching a development copy of your client’s shop. Moreover, you don’t want to have customer data on your server because if something goes wrong, you’re in big big trouble. A simple solution gives:
$ n98-magerun.phar db:dump -s @development [filename]
If you use version control, you’ll most likely find this command useful:
$ n98-magerun.phar db:dump –human-readable -s @development [filename]
(Note that Git seems to handle dump versioning in this form much better.)
At Magently we integrated n98-magerun with our automation framework, therefore, coping databases between developers’ computers and our dev server is done practically automatically. But that’s another story.
List modules
You often have to investigate which modules (and which versions) are installed in a particular Magento instance. You can look through the files or check it in the panel (System > Configuration > Advanced > Disable Modules Output). But there’s also an easier and quicker way to do it:
$ n98-magerun.phar sys:modules:list
This command will give you a table containing codepool, full name, version and the status of all extensions.
What next?
If you like the idea, here are the next steps:
You can download the tool here
You might want to get familiar with the full command list
Also, feel free to share your favourite command in the comment box below.