If your website are causing error and problem because of an update or either by missing configuration, it is very hard to fix especially when you’re not expert on this field troubleshooting everything what causes the error. And If you haven’t taken a snapshot or a image backup of your server before the error occur, your last resort is to back up everything from database, website files and configuration manually. This tutorial is for CentOS server.
In some cases, you just need back up for migration to another server.
To back up your Website Server, you just need the 3 following commands.
Backing up MySQL
We have to back up first our database, to do this you have to identify the database name of your database and do the following command.
mysql -u YOUR_USERNAME -p
SHOW DATABASES;
It will list your databases, now you identify the name of the database you need to back up. Let’s dump all data into a SQL file.
mysqldump -u YOUR_USERNAME -p YOUR_DATABASE_NAME > yourdatabasefile.sql
Your database are now safe. Let’s proceed to the next step.
Compressing and Backing up your Website Files and Configuration
Let’s compress your website files via Tar compression. Feel free to use other compression type.
tar -cvf yourwebsitefile.tar /directory/of/your/files
Now your files are well compressed, the next things we need to do is backup your configuration. Most configuration can be found on your httpd.conf.
tar -cvf httpd.tar /etc/httpd
That’s it! We are now good for deploying this backup files to our other server.
Sending Your Backup files to another Server via SSH
To save time downloading and re-uploading your files to your computer, we just need to send these files to your new server by using the scp command.
scp yourwebsitefile.tar usernameofyournewserver@ipaddressofyournewserver:/path/to/destination/yourwebsitefile.tar
Do the command to other files you just back up. And once it is complete. Login to your new server. To extract the tar, just use the following command:
tar -xvf yourwebsitefile.tar