Backup Drupal database with the command line (without drush)

May 4, 2014

Normally, I use drush to export Drupal databases. Mostly with 'drush bam-backup', after installing the Backup & Migrate module, or with 'drush archive-dump' or 'drush ard'.

Sometimes, backup & migrate isn't working and drush is not installed on the server.

Then the only option to make a decent backup of the database is with the command line, following these steps:

Browse to the file with the command line

Open Terminal and connect with ssh:

ssh user@website

Export the database using mysqldump

Next, we export the database using mysqldump. It doesn't really matter where the database is stored:

mysqldump –u[username] –p[password] [databasename] > [dump file]

For example:

mysqldump –uroot –prootpassword db_test > db_test.sql

Compress the database with the tar command

Lastly, it's a best practice to compress the database:

tar -zcvf databasename.sql.tar.gz directoryname/

This creates an archive in the gzip format, with the verbose and filename flags.

This file can easily be imported in a MySql interface.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.