How to backup SugarCRM from the command line

From the linux command line, these commands let you backup and restore a SugarCRM database.

Update 2016-04-26: Just saw this SugarCRM KB Providing a Backup Without Sensitive Data which is really useful. Thanks Jared.

Firstly, for a proper back up of SugarCRM you’ll need two files, one containing the application files, one containing the SQL database.

First up, the backup…

Backup files:

Change to the folder you want to backup, then…

tar -zcvf CRM-BACKUP-FILES.tar.gz .

Edit: if you get an error ‘Permission Denied’ you may be trying to write to a folder you don’t have permission for, instead try writing to ~/CRM-BACKUP-FILES.tar.gz and it will likely work.
Edit: see also this StackOverflow article.

Backup sql (empty copy of the database):

mysqldump -u USERNAME -p -–no-data DATABASENAME > CRM-BACKUP-SQL.sql

Backup sql (with the data) :

mysqldump -u USERNAME -p DATABASENAME > CRM-BACKUP-SQL.sql

Then you can ‘tar’ the .sql file with

tar -zcvf DATABASENAME-mysql.tar.gz DATABASENAME-mysql.sql

Backup just a single table

mysqldump db_name table_name | gzip > table_name.sql.gz

If you only want the database schema, then in the SugarCRM web application you can do the following:

  • Admin
  • Diagnostic Tool
  • db schema
  • Download that file

Then for the restoration…

Restore files (to current folder):

tar -zxvf CRM-BACKUP-FILES.tar.gz

Restore sql:

mysql -u USERNAME -p DATABASENAME < CRM-BACKUP-SQL.sql

Restore just a single table

gunzip < table_name.sql.gz | mysql -u username -p db_name

These SugarCRM Knowledge Base articles may also be of use:

Backup because only the paranoid survive

I first heard the quote “only the paranoid survive” about 1999 or 2000. But it’s only recently I’ve heard the full quote. Which is:

Success breeds complacency. Complacency breeds failure. Only the paranoid survive.

For more Quotes from Andy Grove visit this quote page.

This thinking applies to so many things, but one I often apply it to is backups. Yes the humble yet oft forgotten backup.

Just because everything is working, and going along swimmingly, we become complacent, we forget or put off doing a backup of our files, our photographs etc. This is when we most need to do our backup, so that when a problem arises, we have that backup to go to.

Thus (and this is the question that prompted me writing this) is “what do I use to backup?”.

I use both Dropbox and Backblaze. You may think they both serve the same purpose. They don’t.

I use Dropbox to make files available to myself across all the platforms I use, and I use it to share files and folders with others. In a sense it backs up my data, but that’s not what it’s there for.

To backup my data, workfiles, photos, music and emails I use Backblaze. Backblaze quietly sits in the background and backs up everything. Those files don’t have to be in my Dropbox folder to be backed up. It’s the easiest, cheapest and most effective offsite backup solution you can implement.

If you aren’t paranoid about losing your files, you don’t need to do anything. If you are, and I am, you need to start backing up. You’ve got no excuses. Complain to me and it’ll fall on deaf ears.