Archive for August, 2010

Importing/Exporting Magento Databases

Posted by: Karen Tuesday, August 24th, 2010

Magento Databases can get pretty big. Here are some commands to help with import/export.

Exporting:

mysqldump -h localhost -u <username> -p <dbname> > <exportname>.sql

Importing:

mysql -h localhost -u <username> -p <dbname> < <importname>.sql
e.g. mysql -h localhost -u karen -p auctionmaid < auctionmaid.sql

If you need to transfer this file off the server via the shell you can do this – see the Putty tools for downloads:

pscp <username>@<remoteip>:<fullpath_to_sql_file>.sql <local_sql_file>.sql
e.g.
pscp root@1.1.1.1:/var/www/vhosts/testsite.com/magdb.sql > magdb.sql

Upgrading your magento site without downtime

Posted by: Karen Tuesday, August 24th, 2010

Before you put on a load of changes to a live site it’s advised to test. Obviously we hope you’ve tested locally, etc, but what if you have an external theme that’s been updated, and how do you test in as close to live as possible?  Here is your answer:

  1. Backup your live database – see here for more info
  2. Backup your Magento site completely
  3. Create a new directory under your magento install called test
  4. Copy the Magento site files into this test directory, maintaining permissions (e.g. tar xvfp)
  5. Make a new database with a new name on your site
  6. Import the live database backup – you may want to disable foreign key checks when doing import
  7. Modify the core_config_table base_urls to point to your test location, e.g. http://www.mysite.com/test/
  8. Modify app/etc/local.xml to use the new database
  9. Run up frontend/backend and make sure is working

You now have a fully working test site.  You can then make your changes on this without affecting the live site.

Once you are happy everything is working you can then either redirect people to use this new location, or do what I do and move your old site to a different subdirectory, and put your new site in the httpdocs folder.

The big advantage of this approach is that if you find an issue a couple of days down the line you can easily just move back to the old server – it’s still there in the background.  I’d advise you switch off checkout so people can’t use the old version.

Tidying Magento Logs

Posted by: Karen Saturday, August 21st, 2010

Many people don’t seem to worry about their logs increasing until their site falls over.  Probably not too wise….

Here are some things you can do to have a bit of a tidy up:

  1. Delete /var/cache occassionally, it does build up rubbish in here, and refreshing from admin doesn’t completely clear it out
  2. Check /var/reports for errors – your customer is seeing these.  Removing then looking again a few days later gives you clues about current issues
  3. Make sure system logging is switched off – in Admin under System->Configuration->Developer->Log Settings
  4. Switch on automated log cleaning using Cron – in Admin under System->Configuration->System, by default this is switched off

If you want to have a big clear out then remove your log files manually from the database via phpmyadmin. EMPTY all the tables beginning with log_ . This isn’t for the faint-hearted, touching the database is always risky so make sure you take a backup.  Optionally you can optimise the tables afterwards.

You’ll be surprised about the amount of space you will recover on your disk if you have never done this. On a busy site you need to be setting the cleaning schedule to every few days.