可以这么说,没有数据库,一切就是个蛋,没有数据库备份,一切还是个蛋,你可以想象数据库备份多么重要。不会linux,不会写shell的朋友麻烦先去补补。不过你说我牛逼,不补也能看懂,那没问题,哈哈,废话不说了
前几篇博客已经相继公开了去转盘网的所有技术细节,如下:
百度网盘爬虫
中文分词算法
邀请好友注册
js分页部分代码
这篇博客我将继续公开数据库自动备份的代码。可以这么说,没有数据库,一切就是个蛋,没有数据库备份,一切还是个蛋,你可以想象数据库备份多么重要。不会linux,不会写shell的朋友麻烦先去补补。不过你说我牛逼,不补也能看懂,那没问题,哈哈,废话不说了。老规矩,上代码:#!/bin/bash<br>
time=$(date +"%d-%m-%Y")<br>
pre=/home/ubuntu #想放到那里麻烦自己配置下哈<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>
fi
注意,我的密码我已经改了,这个不能告诉你们,所以喜欢copy的孩子麻烦自己该密码。下面我教大家玩下crotab,代码如下:# Edit this file to introduce 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 notion 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.log
有用的是最下面的这一句,看到没有,备份完了还得有个log,不然谁知道备份成什么样子了,一点都不懂crontab麻烦自己百度下,我也一时给你讲不明白。
上面是备份的结果,注意,备份完了之后是压缩包的形式,所以请你先安装压缩工具,apt-get install XXXX 不会的还是麻烦百度下,实在简单成狗了。
技术在于分享,开源,去转盘不吝啬任何技术,欢迎关注微博或者微信,随时交流。本人建个qq群,欢迎大家一起交流技术, 群号:512245829 喜欢微博的朋友关注:转盘娱乐即可