How to Backup a WordPress Site from the Command Line

There are 2 things we need to do when we backup a WordPress site.

  1. Backup the WordPress files
  2. Backup The WordPress database

Backup the WordPress files

We can backup the files with tar by running the following command.  Replace (/Path/to/wpdir) with the actual path.

#  tar -zcvf wp-backup.tgz /Path/to/wpdir/

This can take awhile depending on how big your site is.

Backup the Database

The following command will backup the WordPress database into a gziped sql file.

mysqldump -u username -p[root_password] database_name > wp-database.sql && gzip wp-database.sql

You can find the MySQL Database, username, and password in the wp-config.php file in the wordpress directory

You should now have two files, wp-backup.tgz and wp-database.sql.qz, you’ll need both of these to restore the backup.

Leave a Reply