You have backups right? Of coarse you do, but you know what its always a good thing to double check yoru backups right now you know just to make sure.
So now that your back, lets talk about a simple but effective way to create, and backup your databases, lets dive on it!
** This is not the end all be all, but one way that I personally use that has always done me well.
I am going to assume the following two items. 1. Your already SSH’d into your vps, and 2 you already have your site online and ready to go. Now we just need to get it all ready for the world!
So were going to use the WordOps demo I setup over here.
So first thing were going to need to do is get the database credentials from our site. So head over to your site and open up your wp-config.php file.
Now lets grab the DB_NAME, DB_USER, and DB_PASSWORD data and copy them over to your notepad.
Now MySQL has a built in export tool that is very easy to us too, so let check this, first create a folder called backups and then a folder called mysql inside of it.
mkdir -p /backups/mysql
Now we can run the simple command mysqldump by using the following.
mysqldump your_db_name > "$(date +%F).what_have_you".sql
So you can see that a sql backup file was created., and that is it! So lets automate this so it runs everyday at X date and time.
Lets create a simple backup script. Open up your editor of choice, mine is nano.
nano /root/backup.sh
Paste into the file the following.
#!/bin/bash
################################################################
cd /backups/mysql && mysqldump wordpress_theserveradmin_com_jnTlEiP1 > "$(date +%F).wordpress.theserveradmin".sql
Now make the script executable.
chmod +x /root/backup.sh
Now run the script to make sure.
cd /root
./backup.sh
So awesome, now how do we automate this? With cron of coarse!
** Great Read on CronJobs and how to set them.
Now lets edit the crontab and paste our command into it.
nano /etc/crontab
Paste the following to the end of the file: 0 0 * * * root /root/backup.sh 2>&1
Now restart your crond and then you should be good to go for the first part of the backup!