LNMP VPS Website Data backup script (wind station data and MySQL database)

Source: Internet
Author: User
Tags vps mysql database

The importance of Web site backup, believe that every webmaster is know, and now most stationmaster, have used the VPS host, in the Linux operating system, the VPS data backup main is, the website file, the database, the domain name configuration and so on, like the tribe is uses the military elder brother a health installs the package, the operation basically is identical.

Here, we mainly use the script to automate the operation, the contents are as follows:

The code is as follows Copy Code

#!/bin/bash
Mysql_user=root #mysql用户名
mysql_pass=123456 #mysql密码
Web_data=/home/web #要备份的网站数据
Vhost=/usr/local/nginx/conf/vhost #域名配置目录
#压缩网站数据 from Www.111cn.net
Tar zcf/home/wwwroot/backup/web.tar.gz $WEB _data
#压缩域名配置
Tar zcf/home/wwwroot/backup/vhost.tar.gz $VHOST
#导出数据库, a database with a compressed file
For DB in '/usr/local/mysql/bin/mysql-u$mysql_user-p$mysql_pass-b-n-e ' show DATABASES | Xargs '; Todo
(/usr/local/mysql/bin/mysqldump-u$mysql_user-p$mysql_pass ${db} | gzip-9-> ${db}.sql.gz)
Done
#压缩数据库文件为一个文件
Tar zcf/home/wwwroot/backup/data.tar.gz/home/wwwroot/backup/*.sql.gz
Rm-rf/home/wwwroot/backup/*.sql.gz

Here the tribe needs to be explained that you need to modify the database username, password.

There is also a more important, that is, you need your site path to the original path, otherwise you can not complete all the data backup. Of course, no one is going to make any changes to these paths.

Summary

Web site data Backup is a very important work, if you think your host is not particularly secure, the tribe recommends that you perform a backup operation at least once a week. Like tribal words, basically is a monthly backup, mainly to think of the host is still safe, in addition, like pictures of what they have data.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.