Home > php教程 > php手册 > body text

Database scheduled backup principle, code

WBOY
Release: 2016-08-20 08:48:14
Original
1203 people have browsed it

It can be said that without a database, everything is an egg. Without a database backup, everything is still an egg. You can imagine how important database backup is. Friends who don't know Linux or write shell, please go and make up for it first. But if you say I’m awesome and you can understand it without making up for it, then that’s no problem, haha, no more nonsense
The previous blogs have disclosed all the technical details of GoZhuanpan.com, as follows:
Baidu network disk crawler

Chinese word segmentation algorithm

Invite friends to register

js pagination part code

In this blog, I will continue to disclose the code for automatic database backup. It can be said that without a database, everything is an egg. Without a database backup, everything is still an egg. You can imagine how important database backup is. Friends who don't know Linux or write shell, please go and make up for it first. But if you say I’m awesome and you can understand it without supplementing, then that’s no problem, haha, no more nonsense. Old rules, code: #!/bin/bash<br> time=$(date +"%d-%m-%Y")<br> pre=/home/ubuntu #If you want to put it there, please configure it yourself<br> if [ ! -d "$pre/data_backup/$time" ]<br> then<br> mkdir -p $pre/data_backup/$time<br> echo "create $pre/data_backup/$time"<br> else<br> echo "exist $pre/data_backup/$time"<br> fi<br> if [ -d "$pre/data_backup/$time" ]<br> then<br> mysqldump -h10.66.102.75 -uroot -p123456 --opt winrun user > $pre/data_backup/$time/user.sql<br> mysqldump -h10.66.102.75 -uroot -p123456--opt winrun CategoryInfo > $pre/data_backup/$time/CategoryInfo.sql<br> mysqldump -h10.66.102.75 -uroot -p123456 --opt winrun admin_info > $pre/data_backup/$time/admin_info.sql<br> mysqldump -h10.66.102.75 -uroot -p123456 --opt winrun admin_loginfo > $pre/data_backup/$time/admin_loginfo.sql<br> mysqldump -h10.66.102.75 -uroot -p123456 --opt winrun admin_notice_info > $pre/data_backup/$time/admin_notice_info.sql<br> mysqldump -h10.66.102.75 -uroot -p123456--opt winrun advertising_info > $pre/data_backup/$time/advertising_info.sql<br> mysqldump -h10.66.102.75 -uroot -p123456--opt winrun ajax_request_info > $pre/data_backup/$time/ajax_request_info.sql<br> mysqldump -h10.66.102.75 -uroot -p123456 --opt winrun bt_file_info > $pre/data_backup/$time/bt_file_info.sql<br> echo "backup finished"<br> cd $pre/data_backup #enter dir<br> zip -r $time.zip $time/<br> rm -fr $time #delete<br> cd -<br> echo "zip backup database finished"<br> else<br> echo "can not find backup file"<br> fiAttention, I have changed my password. I can’t tell you this, so children who like to copy please change your password yourself. Now I will teach you how to play crotab. The code is as follows: # Edit this file to inroduce tasks to be run by cron.<br> #<br> #Each task to run has to be defined through a single line<br> #indicating with different fields when the task will be run<br> # and what command to run for the task<br> #<br> #To define the time you can provide concrete values ​​for<br> # minute (m), hour (h), day of month (dom), month (mon),<br> # and day of week (dow) or use '*' in these fields (for 'any').#<br> # Notice that tasks will be started based on the cron's system<br> #daemon's notice of time and timezones.<br> #<br> # Output of the crontab jobs (including errors) is sent through<br> # email to the user the crontab file belongs to (unless redirected).<br> #<br> # For example, you can run a backup of all your user accounts<br> # at 5 a.m every week with:<br> # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/<br> #<br> # For more information see the manual pages of crontab(5) and cron(8)<br> #<br> # m h dom mon dow command<br>10 1 * * 1,3,5 /home/backup.sh >> /home/backup.logWhat is useful is the sentence at the bottom. Did you see it? There must be a log after the backup is completed, otherwise who knows What is the backup like? I don’t understand crontab at all. Please download it from Baidu. I can’t explain it to you at the moment.
Database scheduled backup principle, code
The above is the result of the backup. Note that after the backup is completed, it will be in the form of a compressed package, so please install the compression tool first. If you don’t know how to use apt-get install XXXX, you still have to go to Baidu. It’s really easy.

Technology lies in sharing, open source, and don’t skimp on any technology. Welcome to follow Weibo or WeChat and communicate at any time. I have created a QQ group and everyone is welcome to exchange technology together. Group number: 512245829. Friends who like Weibo can follow: Turntable Entertainment

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template