CDatabase Backups and Restore
Backing up Wordpress using mysqldump
cd /opt
mysqldump -u [username] –p[password] [database_name] > [wordpress_backup.sql]
Test the Backup
On the DB Server
Login to MySQL and verify existing data
mysql -u root -p
USE wordpress;
SHOW TABLES; ```
From MySQL Prompt, Delete Wordpress Database
USE mysql
DROP DATABASE WORDPRESS;
[Output: Query OK, 12 rows affected (0.28 sec)]
Validate the wordpress database is deleted
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
Restore
mysql -u root -p < /opt/wordpress_backup.sql
Validate Data Restore
mysql -u root -p
USE wordpress;
SHOW TABLES; ```
Scheduling Daily/Nightly Backups
Create a file wordpress_backup.sh and edit it
vi /root/wordpress_backup.sh
Write backup script for wordpress dump
#!/bin/bash current_date=`date +%Y-%m-%d` sudo mkdir -p ~/wordpress_backup cd ~/wordpress_backup sudo mysqldump -u root -ppassword wordpress > wrodpress_backup_${current_date}.sql
Schedule above script at 12:00 am daily
crontab -e
add below entry in crontab as follow
0 0 * * * /bin/bash /root/wordpress_backup.sh