1. 程式人生 > >如何保持Linux伺服器間的檔案同步(備用)

如何保持Linux伺服器間的檔案同步(備用)

配置rsync
配置/etc/rsyncd.conf檔案:

###########################################################################

uid = nobody
gid = nobody
use chroot = no
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log

[export]
path = /export
ignore errors
read only = true
list = false
hosts allow = 192.168.1.252
hosts deny = 192.168.1.0/24

[user01]
path = /home/user01/backup
ignore errors
read only = true
list = false
hosts allow = 192.168.1.252
hosts deny = 192.168.1.0/24

[user02]
path = /home/user02/user02
ignore errors
read only = true
list = false
hosts allow = 192.168.1.252
hosts deny = 192.168.1.0/24

###########################################################################

修改啟動rsync檔案
[[email protected] etc]# cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it
# allows crc checksumming etc.
service rsync
{
# disable = yes
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[

[email protected] etc]#


經過測試用下面的方法比較好,可以刪除那些DST中SRC沒有的檔案
rsync -vzrtopg --progress --delete 192.168.1.250::export /export
rsync -vzrtopg --progress --delete 192.168.1.250::user02 /home/user02/user02
rsync -vzrtopg --progress --delete 192.168.1.250::user01 /home/user01/backup


我們傳輸的命令模式是:
rsync [OPTION]... [[email protected]]HOST::SRC [DEST]

引數說明:
-v, --verbose 詳細模式輸出
-z, --compress 對備份的檔案在傳輸時進行壓縮處理
-r, --recursive 對子目錄以遞迴模式處理
-t, --times 保持檔案時間資訊
-o, --owner 保持檔案屬主資訊
-p, --perms 保持檔案許可權
-g, --group 保持檔案屬組資訊

--progress 顯示備份過程
--delete 刪除那些DST中SRC沒有的檔案
--exclude "data/" 表示不對/home/user01/backup/data/目錄下的檔案進行備份

下面的命令可以傳輸不包含某個目錄的檔案
rsync -vzrtopg --delete --exclude "data/" --progress 192.168.1.250::user02 /home/user02/user02
rsync -vzrtopg --delete --exclude "data/" --progress 192.168.1.250::user01 /home/user01/backup

製作一個指令碼:
[[email protected] export]# cat autoexport.sh
#!/bin/bash
/usr/bin/rsync -vzrtopg --progress --delete 192.168.1.250::export /export
/usr/bin/rsync -vzrtopg --progress --delete 192.168.1.250::user02 /home/user02/user02
/usr/bin/rsync -vzrtopg --progress --delete 192.168.1.250::user01 /home/user01/backup
[[email protected] export]# chmod 755 autoexport.sh
[[email protected] export]# ./autoexport.sh
receiving file list ...
473 files to consider
./
autoexport.sh
73 100% 71.29kB/s 0:00:00 (xfer#1, to-check=471/473)

sent 92 bytes received 9076 bytes 18336.00 bytes/sec
total size is 147219805 speedup is 16058.01
[[email protected] export]#

通過crontab設定,讓這個指令碼每30分鐘執行一次。執行命令:
# crontab -e
輸入以下一行:
30 * * * * * /export/autoexport.sh

上面的是整點的30分之想,後來更改為:
20,50 * * * * /export/autoexport.sh
讓20和50分的時候執行。


出現的問題:
同步的時候有一些檔案同步不了,
[[email protected] user01]# rsync -vzrtopg --delete --exclude "backup/data/" --progress 192.168.1.250::user01 /home/user01
receiving file list ...
rsync: opendir ".ssh" (in user01) failed: Permission denied (13)
22 files to consider
IO error encountered -- skipping file deletion
./
rsync: send_files failed to open ".bash_history" (in user01): Permission denied (13)
rsync: send_files failed to open ".viminfo" (in user01): Permission denied (13)

sent 127 bytes received 755 bytes 1764.00 bytes/sec
total size is 86396 speedup is 97.95
rsync error: some files could not be backupferred (code 23) at main.c(1298) [generator=2.6.8]
[[email protected] user01]#
在伺服器端執行:
[[email protected] user01]# ls -al
total 60
drwxr-xr-x 5 user01 users 4096 Apr 4 2007 .
drwxr-xr-x 13 root root 4096 Oct 15 08:36 ..
-rwx--x--x 1 user01 users 7053 Apr 3 16:49 .bash_history
-rwxr-xr-x 1 user01 users 24 Jan 5 2007 .bash_logout
-rwxr-xr-x 1 user01 users 191 Jan 5 2007 .bash_profile
-rwxr-xr-x 1 root root 631 Jan 17 2007 .bashrc
-rwxr-xr-x 1 user01 users 237 Jan 5 2007 .emacs
-rwxr-xr-x 1 user01 users 120 Jan 5 2007 .gtkrc
drwxr-xr-x 3 user01 users 4096 Jan 16 2007 .kde
drwx--x--x 2 user01 users 4096 Mar 30 2007 .ssh
drwxr-xr-x 3 user01 users 4096 Mar 24 16:35 backup
-rwx--x--x 1 user01 users 3812 Apr 4 2007 .viminfo
-rwxr-xr-x 1 user01 users 136 Jan 5 2007 .zshrc
[[email protected] user01]# chmod +r .bash_history
[[email protected] user01]# chmod +r .viminfo

重新傳輸的時候出現:
[[email protected] user01]# rsync -vzrtopg --delete --exclude "backup/data/" --progress 192.168.1.250::user01 /home/user01
receiving file list ...
rsync: opendir ".ssh" (in user01) failed: Permission denied (13)
22 files to consider
IO error encountered -- skipping file deletion
.bash_history
7053 100% 6.73MB/s 0:00:00 (xfer#1, to-check=20/22)
.viminfo
3812 100% 3.64MB/s 0:00:00 (xfer#2, to-check=10/22)

sent 127 bytes received 2563 bytes 5380.00 bytes/sec
total size is 86396 speedup is 32.12
rsync error: some files could not be backupferred (code 23) at main.c(1298) [generator=2.6.8]
[[email protected] user01]#


[[email protected] user01]# rsync -vzrtopg --delete --exclude "user02/data/" --progress [email protected]::user02 /home/user02
receiving file list ...
rsync: link_stat "." (in user02) failed: Permission denied (13)
0 files to consider

sent 19 bytes received 17 bytes 72.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files could not be backupferred (code 23) at main.c(1298) [receiver=2.6.8]
[[email protected] user01]#


出現這些問題的原因估計應該是使用者目錄下的隱藏檔案造成的。
原來/etc/rsyncd.conf檔案中設定的目錄是/home/user01,後臺設定的是/home/user01/backup.設定後就可以同步。


相關推薦

如何保持Linux伺服器檔案同步(備用)

配置rsync 配置/etc/rsyncd.conf檔案: ########################################################################### uid = nobody gid = nobody use c

Linux伺服器檔案實時同步的實現

使用場景 現有伺服器A和伺服器B,如果伺服器A的指定目錄(例如 /home/paul/rsync/ )中的內容發生變更(增刪改和屬性變更),實時將這些變更同步到伺服器B的目標目錄中(例如 /home/paul/rsync/ )。 資料映象備份工具Rsync Rsy

關於解決多臺linux伺服器檔案實時同步問題

  最近要做一個相關的解決方案,在虛擬機器測試沒有問題。給大家分享出來,有更好的解決方案,歡迎討論。 1.1 inotify相關介紹      1、rsync        與傳統的cp、ta

使用nodepad++連線Linux伺服器實現檔案編輯儲存同步

1.下載並安裝nodpad++軟體 2.下載並安裝NppFtp外掛,並將下載後的外掛複製到nodpad++的安裝目錄 3.重啟nodpa++軟體,找到外掛NppFtp 配置連線資訊 4.開始連線遠端伺服器 5.測試連線結果

linux伺服器免密登入

假設要登入的機器為192.168.175.5,當前登入的機器為192.168.175.4。 1  首先在4的機器上生成金鑰(如果已經生成可以跳過):      $ ssh-keygen -t rsa  (注意:ssh和-keygen沒有空

Shell-case:叢集中伺服器實時同步

      今天和大家分享一個比較常見的技術,實時同步技術,在叢集中,很多裝置的內容都是一樣的,裝的時候可以用克隆的方法,但後來有的時候需要進行修改,我們就要一模一樣的操作每個機子,這就很麻煩,我們就希望可以修改其中一個機子後,自動同步到其他伺服器上,這時候就要用到 r

Linux命令之檔案同步、定時備份 -rsync,cron,crontab

一、rsync介紹(可忽略) Rsync(remote synchronize)是一個遠端檔案同步工具; Rsync使用“Rsync演算法”來同步檔案,該演算法只傳送兩個檔案的不同部分,因此速度相當快; Rsync是替代rcp的一個工具,目前由rsync.

建立linux伺服器互信

訴求:jenkins部署流水線指令碼中,需要跨內部linux伺服器進行通訊,為此去建立兩臺linux伺服器互信,進行免密登入。 1、首先保證兩臺伺服器(如本次需打通233、170間通訊)是可通訊的,處在相同區域網、彼此在互信白名單中,通過密碼或金鑰可互相訪問; 2

java使用Jsch實現遠端操作linux伺服器進行檔案上傳、下載,刪除和顯示目錄資訊

1 package com.fline.aic.utils; 2 3 import java.io.BufferedReader; 4 import java.io.File; 5 import java.io.FileInputStream; 6 import jav

Linux中df命令:用來檢查linux伺服器檔案系統的磁碟空間佔用情況

linux中df命令的功能是用來檢查linux伺服器的檔案系統的磁碟空間佔用情況。可以利用該命令來獲取硬碟被佔用了多少空間,目前還剩下多少空間等資訊。 1.命令格式: df [選項] [檔案] 2.命令功能: 顯示指定磁碟檔案的可用空間。如果沒有檔名被指定,則所有

分享Windows伺服器網站檔案同步備份解決方案之cwRsyn進行檔案同步

本文和大家分享Windows伺服器網站檔案同步備份解決方案,來自部落格園dudu的文章。對於一個網站來說,使用者上傳檔案的同步備份是必需要解決的問題。對於有著巨量上傳檔案的大型網站,一般採用分散式儲存系統。而對於上傳檔案量不是很大的網站,只要在另外一臺伺服器上儲存上傳檔案的同

Linux伺服器檔案上傳下載使用

一、登入說明:ssh [email protected]   //登入機器的使用者名稱user,後面是ip地址; 查詢檔案: find / -name "libstdc++.so*"常見有使用:scp命令、xshell軟體裡的xftp程式、U盤掛載、伺服器自帶的lr

通過Xshell如何從Linux伺服器下載檔案

利用Xshell登入Linux伺服器,安裝lrzsz檔案接收發送軟體。 #cd /media/CentOS_6.6_Final/Packages #rpm -ivh lrzsz*.rpm

在遠端Linux伺服器中備份MySQL資料庫,通過scp將遠端Linux伺服器檔案下載到本地Linux電腦中

1.首先登入到遠端伺服器(ip 10.46.2.228),可通過ssh方式登入,確保ssh服務和22埠正常才能使用scp命令下載檔案; 2.執行命令 mysqldump -u root -p mysql(要匯出的資料庫名) > mysql.sql(匯出資料庫儲存檔名

putty windows上傳檔案linux伺服器 & 從linux伺服器 下載檔案到 windows

使用pscp方式從windows上傳檔案到linux伺服器 在CMD命令列中進入到putty安裝目錄 輸入pscp 回車 pscp 跟我們平時使用的linux scp命令操作的都是類似的 現在我直接從windows本地上傳一個檔案到linux伺服器 D:\P

Linux 使用 sftp 向linux伺服器傳輸檔案

使用 sftp 向linuxsftp是加密的檔案傳輸。 1.登陸 sftp [email protected] 2.把本地檔案name1傳到伺服器name2下 put

Linux 伺服器如何檔案和資料夾的讀寫許可權

把index.htm 檔案修改為可寫可讀可執行:chmod 777 index.htm 要修改目錄下所有檔案屬性可寫可讀可執行:chmod 777 *.* 該命令中可以使用 * 作為萬用字元。 比如:修改所有htm檔案的屬性:chmod 777 *.htm 修改資料夾

求助:linux伺服器Socket異常問題:Connection reset

在一臺伺服器上有兩個tomcatA、tomcatB; tomcatA上部署了專案a以專門對外提供Webservice服務; tomcatB上部署了針對 專案a 的web測試專案; 需求是:通過web測試專案對專案a提供的各種Webservice服務進行測試; 現在的問題:在

Linux從一臺linux伺服器檔案到另一臺linux伺服器-適合斷點續傳(備份)

例如將svn的資料sd的目錄(目錄位於114.235.23.11伺服器)備份到114.235.23.100 支援斷點續傳。 sd所在目錄為/home/aaa/sd 所在伺服器:114.235.23.1

linux 伺服器之間檔案拷貝

    跨伺服器拷貝需要用到的命令是scp. ----------------------拷貝資料夾---------------------------------------------- 把當