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
echo '[mysqldump]'> ~/.my.cnf; echo 'user=Site1WPUSR'>> ~/.my.cnf; echo 'password=Site1WPUSRPWD' >> ~/.my.cnf; chmod 0600 ~/.my.cnf
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
Last Updated on February 22, 2016