WordPress – Backup & Restore

| |

I have this in these two posts (CentOS – WordPress Install and Ubuntu – WordPress Install) but thought it may be best to create a separate post to help focus on this process.

After writing this post I came across a site that I do not have SSH/CLI access to so I needed to have another option. If you do not have SSH/CLI access it’s best to use the process on PHP – WordPress Backup (MySQL & Files).

Backup

The purpose of this step is to have a quick repeatable command to backup and restore a database.
Log in as your username with website rights (not root) and run this command
For our purposes the values we use can be changed to suit your needs:

  • Database: Site1WPDB
  • Username: Site1WPUSR
  • Password: Site1WPUSRPWD
mysqldump -u Site1WPUSR Site1WPDB > ~/WordPress_DB_Backup_`date +"%m-%d-%Y_%I-%M-%S"`.sql
tar -zcvf WordPress_Site_Backup_`date +"%m-%d-%Y_%I-%M-%S"`.tar.gz /var/www/html

Restore

Make sure you modify the date of the file to what you want to restore from.

mysql -u Site1WPUSR Site1WPDB < ~/WordPress_DB_Backup_08-27-2015.sql
Originally Posted on January 28, 2016
Last Updated on February 22, 2016
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.