您好,登錄后才能下訂單哦!
前幾篇博客已經相繼公開了去轉盤網的所有技術細節,如下:
百度網盤爬蟲
中文分詞算法
邀請好友注冊
js分頁部分代碼
這篇博客我將繼續公開數據庫自動備份的代碼。可以這么說,沒有數據庫,一切就是個蛋,沒有數據庫備份,一切還是個蛋,你可以想象數據庫備份多么重要。不會linux,不會寫shell的朋友麻煩先去補補。不過你說我牛逼,不補也能看懂,那沒問題,哈哈,廢話不說了。老規矩,上代碼:
#!/bin/bash time=$(date +"%d-%m-%Y") pre=/home/ubuntu #想放到那里麻煩自己配置下哈 if [ ! -d "$pre/data_backup/$time" ] then mkdir -p $pre/data_backup/$time echo "create $pre/data_backup/$time" else echo "exist $pre/data_backup/$time" fi if [ -d "$pre/data_backup/$time" ] then mysqldump -h20.66.102.75 -uroot -p123456 --opt winrun user > $pre/data_backup/$time/user.sql mysqldump -h20.66.102.75 -uroot -p123456--opt winrun CategoryInfo > $pre/data_backup/$time/CategoryInfo.sql mysqldump -h20.66.102.75 -uroot -p123456 --opt winrun admin_info > $pre/data_backup/$time/admin_info.sql mysqldump -h20.66.102.75 -uroot -p123456 --opt winrun admin_loginfo > $pre/data_backup/$time/admin_loginfo.sql mysqldump -h20.66.102.75 -uroot -p123456 --opt winrun admin_notice_info > $pre/data_backup/$time/admin_notice_info.sql mysqldump -h20.66.102.75 -uroot -p123456--opt winrun advertising_info > $pre/data_backup/$time/advertising_info.sql mysqldump -h20.66.102.75 -uroot -p123456--opt winrun ajax_request_info > $pre/data_backup/$time/ajax_request_info.sql mysqldump -h20.66.102.75 -uroot -p123456 --opt winrun bt_file_info > $pre/data_backup/$time/bt_file_info.sql echo "backup finished" cd $pre/data_backup #enter dir zip -r $time.zip $time/ rm -fr $time #delete cd - echo "zip backup database finished" else echo "can not find backup file" fi
注意,我的密碼我已經改了,這個不能告訴你們,所以喜歡copy的孩子麻煩自己該密碼。下面我教大家玩下crotab,代碼如下:
# Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command 10 1 * * 1,3,5 /home/backup.sh >> /home/backup.log
有用的是最下面的這一句,看到沒有,備份完了還得有個log,不然誰知道備份成什么樣子了,一點都不懂crontab麻煩自己百度下,我也一時給你講不明白。
上面是備份的結果,注意,備份完了之后是壓縮包的形式,所以請你先安裝壓縮工具,apt-get install XXXX 不會的還是麻煩百度下,實在簡單成狗了。
技術在于分享,開源,去轉盤不吝嗇任何技術,歡迎關注微博或者微信,隨時交流。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。