Sunday, September 28, 2014

Backup & Restore WordPress on a VPS [Part 2] - How to do it manually

When using the VPS then manipulate the command line to yourself data backup and recovery craft on which you certainly have to become more flexible understanding that we are not always able to rely on tools automation.
In this article, I will show you how to backup the data on the VPS website. And other data such as configuration of VPS, Webserver, ... then you should download the file to your computer for storage, the better.

I. Install the required software

In this manual backup, I will use the zip and unzip because this command is easier to use the command tar more. Therefore, you should make sure that you have installed VPS ZIP software by running the following command to install:
1
sudo  yum install  unzip zip y

II. Backup and restore source code

2.1) Backup source code

To back up files and folders in the source code of the website on VPS, we will use thezip with the following structure:
1
zip [options] [name- file -creation arm] [mail-item-to-compression]
In particular, the [option] will have a lot of options, but most I just use an option that is -r : always mean that will compress the entire file in the subfolders of the folder to compress.
For example, you have the source code in the VirtualHost paths/home/webdata/thachpham.dev/public_html and I need all the compressed files and folders in a file name that is thachpham.zip would be written as follows:
1
zip -r thachpham.zip / home / webdata / thachpham .dev / public_html / *
After compression is complete, the file will be saved in thachpham.zip folder you are browsing is not written clearly they need to save the file path. If you need to save thachpham.zip file into the directory / home / backup / it will write as follows:
1
zip -r / home / backup / thachpham  / home / webdata / thachpham .dev / public_html / *
But one place you note, if you do not cd into the directory to zip it as zip, it will collect the entire directory tree into. For example, in the command form, when it will be unpacked folder /home/webdata/thachpham.dev/public_html not only the source code is not.
Therefore, it is best if you need to zip up the cd to the directory first, then zip back like the following example:
1
2
3
cd  / home / webdata / thachpham .dev / public_html
 
zip -r thachpham *
1
2
3
4
5
[Root @ hocvps ~] # ls -al / home / backup
total 15 432
drwxr-xr-x 2 root root 4096 Sep 24 09:12.
drwxr-xr-x 4 root root 4096 Sep 24 09:12 ..
rw-r - 1 root root 15,792,563 r-- Sep 24 09:12 thachpham.zip

2.2) source code Restore from backup file

To recover data, also known as exhaust compressed backup data, you can use the command unzip if it is zip file that you have done in the way. Unzip command structure is as follows:
1
unzip [option-select] [name- file ] d [name-roads-lead-to-save]
In the options, please use your best option o to overwrite the old files in the folder to unzip if any.
For example, I have thachpham.zip file saved in / home / backup / and need to unzip the folder /home/webdata/thachpham.dev/public_html would be written as follows:
1
unzip o / home / backup / thachpham zip d / home / webdata / thachpham .dev / public_html

III. Backup & Restore database

For databse is also not that difficult where only one single command. However, backup and recovery commands will be a little bit different.

3.1) Backup the database

To backup the database, we'll use the command mysqldump structure:
1
mysqldump u [name database username]-p [name of the database for backup]> [name of file  to save] .sql
For example, I have one database named dulieu1 with the database username isdulieu1_user and need to backup to a file named thachpham-data.sql the write command as follows:
1
mysqldump u p dulieu1 dulieu1_user> thachpham-data.sql
It will ask for the password of the database user you enter in it. If you do not want to type a password after running the command, write -p123456 , 123456 is the password database.
Backup is complete, the file will be saved .sql in the current directory that you are visiting, want it automatically transferred into another folder when backup is complete, just add a specific path in the file name to save .sql.

3.2) Restore database

To restore the database using mysqldump that was not going to use the commandmysql with the shaft:
1
u mysql [database name username]-p [name of the database to be restored] <[name of file  to restore .sql]
For example:
1
mysql u dulieu1_user -p123456 dulieu1 <thachpham-data.sql
Note that if your database is the best data and delete data and then recreate a new database and imported goods because it does not support the override.
Deleting database in SQL statement is DROP DATABASE name-data-to-remove,.

Epilogue

In this article, I just need you to know that only radical but this is very important and should be useful later if you are not familiar command then tap it familiar.
In the following article, I will guide you to manually create a backup command line support like your attention instead of typing each piece zip and mysqldump very lose and less professional.

0 nhận xét:

Post a Comment