There are 2 things we need to do when we backup a WordPress site.
- Backup the WordPress files
- 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.