mysqlDatabase Backup並且實現遠程複製

來源:互聯網
上載者:User

標籤:style   io   ar   os   for   sp   檔案   資料   div   

一.實現ssh 遠程登陸

機器環境:

192.167.33.108 clent 使用者:crawler

192.167.33.77 server 使用者:crawler

1.用戶端 產生密鑰

/home/crawler/.ssh/ssh-keygen

2. 查看密鑰檔案許可權

ls -ld ~/.ssh; ls -l ~/.ssh

3.修改檔案許可權

chmod 700 /home/crawler/.ssh

chmod 600 /home/crawler/.ssh/id_rsa

4.複製公開金鑰到伺服器端

scp -r /home/crawler/.ssh/id_rsa.pub [email protected]:/home/crawler/.ssh

5.伺服器端設定公開金鑰

ls -ld /home/crawler/.ssh 查看檔案許可權 
chmod 700 /home/crawler/.ssh 需要是drwx
ls -l /home/crawler/.ssh/*pub 查看是否有公開金鑰
cat /home/crawler/.ssh/id_rsa.pub >> /home/crawler/.ssh/authorized_keys //產生公開金鑰最好用這種方式避免替換掉之前的公開金鑰
chmod 644 /home/crawler/.ssh/authorized_keys //修改許可權
ls -l /home/crawler/.ssh // 查看許可權

6.ssh [email protected] 登陸成功

 

二、備份mysql資料庫

1.備份指令碼(每天淩晨3點30開始備份,只保留7天的備份資料)

30 03 * * * sh /home/crawler/mysql_back_up/script/mysql-backup.sh gquan_miss8

 

rq=` date +%Y%m%d `

echo backuping $1

mysqldump -uroot -p111111 --default-character-set=utf8 --opt  --triggers -R --hex-blob --single-transaction  $1 | gzip > /home/crawler/mysql_back_up/daily/$1-all-$rq.sql.gz

find  /home/crawler/mysql_back_up/daily  -mtime +7 -name "*.sql.gz"  -exec  rm -rf {} \;

echo finished backup $1

2.rsync實現遠程備份資料增量同步處理(每天淩晨5點10分執行)

10 05 * * * sh /home/crawler/mysql_back_up/script/back_mysql_77.sh >> /home/crawler/mysql_back_up/script/back.log

#!/bin/sh
echo "------------------------start--------------"`date`
rsync -au --delete /home/crawler/mysql_back_up/daily/ [email protected]:/home/crawler/back_96_data
echo "------------------------over--------------"`date

3.測試查看伺服器上面有client檔案說明正確

server圖片

client 圖片

 

 

 

 

 



mysqlDatabase Backup並且實現遠程複製

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.