




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、使用Linux的rsync命令實現(xiàn) 多服務(wù)器鏡像同步 實現(xiàn)功能:當(dāng)用戶在本地客戶端某目錄內(nèi)建立、修改、刪除目錄或文件、修改目錄或文件的屬性,只要執(zhí)行相同的shell腳本,rsync就會自動找出有改動或刪除的數(shù)據(jù),將其傳送到服務(wù)器上,使Linux服務(wù)器端某目錄內(nèi)的數(shù)據(jù)跟本地客戶端某目錄內(nèi)的數(shù)據(jù)保持一致。方式一:一、服務(wù)器端(例:*):1、創(chuàng)建用戶和組 groupadd www -g 48 useradd -u 48 -g www www mkdir -p /opt/htdocs chmod +w /opt/htdocs chown www:www /opt/htdocs 2、編輯rsync的配置
2、文件 vi /etc/rsyncd.conf 輸入以下內(nèi)容: uid=www gid=www max connections=10 use chroot=no log file=/var/log/rsyncd.log pid file=/var/run/rsyncd.pid lock file=/var/run/rsyncd.lock zhangyan path=/opt/htdocs comment = my htdocs ignore errors read only = no hosts allow=1 2 3、啟動rsync服務(wù)器端 /usr/bin/rsync -daemon 二、客
3、戶端(例:1和2): 1、創(chuàng)建一個shell腳本push.sh vi push.sh 輸入以下內(nèi)容(*為要推送到的目標(biāo)服務(wù)器,zhangyan為服務(wù)器端rsyncd.conf配置文件中的模塊名): 引用 #!/bin/sh /usr/bin/rsync -vzrtopg -delete $1 0:zhangyan/ /usr/bin/rsync -vzrtopg -delete $1 1:zhangyan/ /usr/bin/rsync -vzrtopg -delete $1 6:zhangyan/ /usr/bin/rsync -vzrtopg -delete $1 9:zhangyan/
4、注:因為是內(nèi)部局域網(wǎng)之間傳輸,這里沒有設(shè)置密碼。 2、賦予push.sh執(zhí)行權(quán)限 chmod +x ./push.sh 3、同步推送客戶端某個目錄中(例:/home/zhanguan/abc)的文件到服務(wù)器端的/opt/htdocs目錄: ./push.sh /home/zhanguan/abc/ 注意:不要忘了abc后面的/。如果更改的文件太大,可以在上面語句的末尾加上空格和&號,推到后臺執(zhí)行。例: ./push.sh /home/zhanguan/abc/ & 方式二: 一、服務(wù)器端(例:*): 1、創(chuàng)建用戶和組 groupadd www -g 48 useradd -u 48 -g ww
5、w www mkdir -p /opt/htdocs chmod +w /opt/htdocs chown www:www /opt/htdocs passwd www 為www用戶設(shè)置一個密碼。 二、客戶端: 1、同步推送客戶端某個目錄中(例:/home/zhanguan/abc)的文件到服務(wù)器端的/opt/htdocs目錄: /usr/bin/rsync -vzrtopg -delete /home/zhanguan/abc/ -e ssh www0:/opt/htdocs/ 輸入密碼,回車即可,無須服務(wù)器端啟動rsync服務(wù)。使用Linux的rsync命令實現(xiàn):多服務(wù)器鏡像同步實現(xiàn)功能:
6、當(dāng)用戶在本地客戶端某目錄內(nèi)建立、修改、刪除目錄或文件、修改目錄或文件的屬性,只要執(zhí)行相同的shell腳本,rsync就會自動找出有改動或刪除的數(shù)據(jù),將其傳送到服務(wù)器上,使服務(wù)器端某目錄內(nèi)的數(shù)據(jù)跟本地客戶端某目錄內(nèi)的數(shù)據(jù)保持一致。一、通過rsh或ssh命令在沒有建立rsync服務(wù)器的情況下,我們可以利用rsync命令直接進(jìn)行快速的差異備份:命令格式:#rsync option 源路徑 目標(biāo)路徑其中:option:a:使用archive模式,等于-rlptgoD,即保持原有的文件權(quán)限z:表示傳輸時壓縮數(shù)據(jù)v:顯示到屏幕中e:使用遠(yuǎn)程shell程序(可以使用rsh或ssh)-delete:精確保存副
7、本,源主機(jī)刪除的文件,目標(biāo)主機(jī)也會同步刪除-include=PATTERN:不排除符合PATTERN的文件或目錄-exclude=PATTERN:排除所有符合PATTERN的文件或目錄-password-file:指定用于rsync服務(wù)器的用戶驗證密碼源路徑和目標(biāo)路徑可以使用如下格式:rsync:/USERHost:Port/Path -rsync服務(wù)器路徑USERHost:Path -rsync服務(wù)器的另一種表示形式USERHost:Path -遠(yuǎn)程路徑LocalPath rsync.password$ rsync -avzP -delete -password-file=rsync.pas
8、sword HYPERLINK mailto:linuxsir linuxsir:linuxsirhome linuxsirhome注:這樣就不需要密碼了;其實這是比較重要的,因為服務(wù)器通過crond計劃任務(wù)還是有必要的;(3)讓rsync 客戶端自動與服務(wù)器同步數(shù)據(jù)第一步:創(chuàng)建同步腳本和密碼文件roottest228 data# mkdir /etc/cron.daily.rsyncroottest228 data# cd /etc/cron.daily.rsyncroottest228 cron.daily.rsync# touch root.sh oracle.shroottest228
9、 cron.daily.rsync# chmod 755 /etc/cron.daily.rsync/*.shroottest228 cron.daily.rsync# mkdir /etc/rsyncd/roottest228 cron.daily.rsync# touch /etc/rsyncd/rsyncroot.passwdroottest228 cron.daily.rsync# touch /etc/rsyncd/rsyncoracle.passwdroottest228 cron.daily.rsync# chmod 600 /etc/rsyncd/rsync*注: 我們在 /e
10、tc/cron.daily/ 中創(chuàng)建了兩個文件oracle.sh和root.sh ,并且是權(quán)限是 755的。創(chuàng)建了兩個密碼文件,root用戶用的是 rsyncroot.passwd ,而oracle用戶用的是 rsyncoracle.password ,權(quán)限是600roottest228 cron.daily.rsync# vi /etc/cron.daily.rsync/root.sh#!/bin/sh# home backup/usr/bin/rsync -avzP -password-file=/etc/rsyncd/rsyncroot.passwd HYPERLINK mailto:r
11、oot27 root27:oraclepackages /u01/packages/$(date +%m-%d-%y)roottest228 cron.daily.rsync# vi /etc/cron.daily.rsync/oracle.sh#!/bin/sh# home backup/usr/bin/rsync -avzP -password-file=/etc/rsyncd/rsyncoracle.passwd HYPERLINK mailto:oracle27 oracle27:oraclepackages /u01/packages/$(date +%m-%d-%y)注:你可以把r
12、oot.sh 和oracle.sh 的內(nèi)容合并到一個文件中,比如都寫到 root.sh 中;接著我們修改 /etc/rsyncd/rsyncroot.passwd 和 rsyncoracle.passwd的內(nèi)容roottest228 cron.daily.rsync# echo root /etc/rsyncd/rsyncroot.passwdroottest228 cron.daily.rsync# echo oracle /etc/rsyncd/rsyncoracle.passwd然后我們再/home目錄下創(chuàng)建root 和oracle兩個目錄(也可以在需要同步到目的文件夾下創(chuàng)建相關(guān)文件目錄
13、),意思是服務(wù)器端的oraclepackages數(shù)據(jù)同步到備份服務(wù)器上的 /home/roothome下, oraclepackages(或相關(guān)的文件)數(shù)據(jù)同步到 /home/oraclehome/目錄下。并按年月日歸檔創(chuàng)建目錄;每天備份都存檔;roottest228 cron.daily.rsync# mkdir /u01/packages第二步:修改crond服務(wù)器的配置文件roottest228 cron.daily.rsync# crontab -e# Run daily cron jobs at 4:10 every day backup linuxsir data:10 4 * *
14、 * /usr/bin/run-parts /etc/cron.daily.rsync 1 /dev/null注:第一行是注釋,是說明內(nèi)容,這樣能自己記住。第二行表示在每天早上4點(diǎn)10分的時候,運(yùn)行 /etc/cron.daily.rsync 下的可執(zhí)行腳本任務(wù);第三步:重啟crond服務(wù)器;配置好后,要重啟crond 服務(wù)器roottest228 cron.daily.rsync# killall crond 注:殺死crond 服務(wù)器的進(jìn)程roottest228 cron.daily.rsync# ps aux|grep crond 注:查看一下是否被殺死;root 8094 0.0 0.
15、0 4016 616 pts/1 S+ 18:45 0:00 grep crondroottest228 cron.daily.rsync# /usr/sbin/crond 注:啟動 crond 服務(wù)器roottest228 cron.daily.rsync# ps aux|grep crond 注:查看一下是否啟動了?root 8096 0.0 0.0 6052 988 ? Ss 18:45 0:00 /usr/sbin/crondroot 8098 0.0 0.0 3952 620 pts/1 S+ 18:46 0:00 grep crond在 Windows 上使用 rsync 同步文件
16、和目錄rsync 是一個 Unix 系統(tǒng)下的自由的計算機(jī)程序,它可以用來從一個地方同步文件和目錄到另外一個地方,而且它使用一種 delta 編碼方式來使得所需要傳輸?shù)臄?shù)據(jù)是盡可能的少。它被大量使用于站點(diǎn)鏡像上。這里介紹如何在 Windows 系統(tǒng)下來部署 rsync 服務(wù)器,并使用客戶端同步文件和目錄。一.安裝和部署服務(wù)器端首先去下載一個為 Windows 平臺開 發(fā)的 rsync server:cwRsync Server ,下載后安裝和一般的 Windows 安裝程序一樣,一直點(diǎn)那個“下一步”(Next)就完事了。然后修改一下配置,默認(rèn)安裝情況下,配置文件在 C:Program Files
17、cwRsyncServerrsyncd.conf ,默認(rèn)配置內(nèi)容如下:use chroot = falsestrict modes = falsehosts allow = *log file = rsyncd.logpid file = rsyncd.pid# Module definitions# Remember cygwin naming conventions : c:work becomes /cygwin/c/work#testpath = /cygdrive/c/workread only = falsetransfer logging = yes根 據(jù)這段配置你很容易做出自己
18、的配置修改,特別注意的是要把路徑 c:work 改成 /cygwin/c/work,修改完配置后,去 Windows 的服務(wù)管理器里面找到 RsyncServer 這一條,把它的屬性中的啟動類型從“手動”改為“自動,這樣下次開機(jī)就會自動運(yùn)行了,你也可以立即將該服務(wù)啟動起來。注意 rsync server 會監(jiān)聽 873 端口,所以如果你有開啟防火墻,不要忘了開放 873 端口。二.安裝客戶端然后你可以安裝一個客戶端,cwRsync,也可以在剛才下載 cwRsync Server 的網(wǎng)站上找到,安裝同樣很簡單,安裝完成后建議你把 C:Program FilescwRsyncbin (默認(rèn)安裝情況
19、下)加入到操作系統(tǒng)環(huán)境變量的 PATH 參數(shù)中去,然后就可以在命令行里用命令 rsync 來做同步等操作了:1.打印幫助:C:rsycn -helprsync version 2.6.9 protocol version 29Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.Capabilities: 64-bit files, socketpairs, hard links, symlinks, batchfiles,inplace, no IPv6, 64-bit system inums, 64-b
20、it internal inumsrsync comes with ABSOLUTELY NO WARRANTY. This is free software, and youare welcome to redistribute it under certain conditions. See the GNUGeneral Public Licence for details.rsync is a file transfer program capable of efficient remote updatevia a fast differencing algorithm.Usage: r
21、sync OPTION. SRC SRC. DESTor rsync OPTION. SRC SRC. USERHOST:DESTor rsync OPTION. SRC SRC. USERHOST:DESTor rsync OPTION. SRC SRC. rsync:/USERHOST:PORT/DESTor rsync OPTION. USERHOST:SRC DESTor rsync OPTION. USERHOST:SRC DESTor rsync OPTION. rsync:/USERHOST:PORT/SRC DESTThe : usages connect via remote
22、 shell, while : & rsync:/ usages connectto an rsync daemon, and require SRC or DEST to start with a module name.Options-v, -verbose increase verbosity-q, -quiet suppress non-error messages-no-motd suppress daemon-mode MOTD (see manpage caveat)-c, -checksum skip based on checksum, not mod-time & size
23、-a, -archive archive mode; same as -rlptgoD (no -H)-no-OPTION turn off an implied OPTION (e.g. -no-D)-r, -recursive recurse into directories-R, -relative use relative path names-no-implied-dirs dont send implied dirs with -relative-b, -backup make backups (see -suffix & -backup-dir)-backup-dir=DIR m
24、ake backups into hierarchy based in DIR-suffix=SUFFIX set backup suffix (default w/o -backup-dir)-u, -update skip files that are newer on the receiver-inplace update destination files in-place (SEE MAN PAGE)-append append data onto shorter files-d, -dirs transfer directories without recursing-l, -li
25、nks copy symlinks as symlinks-L, -copy-links transform symlink into referent file/dir-copy-unsafe-links only unsafe symlinks are transformed-safe-links ignore symlinks that point outside the source tree-k, -copy-dirlinks transform symlink to a dir into referent dir-K, -keep-dirlinks treat symlinked
26、dir on receiver as dir-H, -hard-links preserve hard links-p, -perms preserve permissions-E, -executability preserve the files executability-chmod=CHMOD affect file and/or directory permissions-o, -owner preserve owner (super-user only)-g, -group preserve group-devices preserve device files (super-us
27、er only)-specials preserve special files-D same as -devices -specials-t, -times preserve times-O, -omit-dir-times omit directories when preserving times-super receiver attempts super-user activities-S, -sparse handle sparse files efficiently-n, -dry-run show what would have been transferred-W, -whol
28、e-file copy files whole (without rsync algorithm)-x, -one-file-system dont cross filesystem boundaries-B, -block-size=SIZE force a fixed checksum block-size-e, -rsh=COMMAND specify the remote shell to use-rsync-path=PROGRAM specify the rsync to run on the remote machine-existing skip creating new fi
29、les on receiver-ignore-existing skip updating files that already exist on receiver-remove-source-files sender removes synchronized files (non-dirs)-del an alias for -delete-during-delete delete extraneous files from destination dirs-delete-before receiver deletes before transfer (default)-delete-dur
30、ing receiver deletes during transfer, not before-delete-after receiver deletes after transfer, not before-delete-excluded also delete excluded files from destination dirs-ignore-errors delete even if there are I/O errors-force force deletion of directories even if not empty-max-delete=NUM dont delet
31、e more than NUM files-max-size=SIZE dont transfer any file larger than SIZE-min-size=SIZE dont transfer any file smaller than SIZE-partial keep partially transferred files-partial-dir=DIR put a partially transferred file into DIR-delay-updates put all updated files into place at transfers end-m, -pr
32、une-empty-dirs prune empty directory chains from the file-list-numeric-ids dont map uid/gid values by user/group name-timeout=TIME set I/O timeout in seconds-I, -ignore-times dont skip files that match in size and mod-time-size-only skip files that match in size-modify-window=NUM compare mod-times w
33、ith reduced accuracy-T, -temp-dir=DIR create temporary files in directory DIR-y, -fuzzy find similar file for basis if no dest file-compare-dest=DIR also compare destination files relative to DIR-copy-dest=DIR . and include copies of unchanged files-link-dest=DIR hardlink to files in DIR when unchan
34、ged-z, -compress compress file data during the transfer-compress-level=NUM explicitly set compression level-C, -cvs-exclude auto-ignore files the same way CVS does-f, -filter=RULE add a file-filtering RULE-F same as -filter=dir-merge /.rsync-filterrepeated: -filter=- .rsync-filter-exclude=PATTERN ex
35、clude files matching PATTERN-exclude-from=FILE read exclude patterns from FILE-include=PATTERN dont exclude files matching PATTERN-include-from=FILE read include patterns from FILE-files-from=FILE read list of source-file names from FILE-0, -from0 all *-from/filter files are delimited by 0s-address=
36、ADDRESS bind address for outgoing socket to daemon-port=PORT specify double-colon alternate port number-sockopts=OPTIONS specify custom TCP options-blocking-io use blocking I/O for the remote shell-stats give some file-transfer stats-8, -8-bit-output leave high-bit chars unescaped in output-h, -huma
37、n-readable output numbers in a human-readable format-progress show progress during transfer-P same as -partial -progress-i, -itemize-changes output a change-summary for all updates-out-format=FORMAT output updates using the specified FORMAT-log-file=FILE log what were doing to the specified FILE-log
38、-file-format=FMT log updates using the specified FMT-password-file=FILE read password from FILE-list-only list the files instead of copying them-bwlimit=KBPS limit I/O bandwidth; KBytes per second-write-batch=FILE write a batched update to FILE-only-write-batch=FILE like -write-batch but w/o updatin
39、g destination-read-batch=FILE read a batched update from FILE-protocol=NUM force an older protocol version to be used-version print version number(-h) -help show this help (-h works with no other options)Use rsync -daemon -help to see the daemon-mode command-line options.Please see the rsync(1) and
40、rsyncd.conf(5) man pages for full documentation.See url/url for updates, bug reports, and answers2.列出 rsync server 端的 modules:c:rsync rsync:/rsync-server-iptest3.列出 module test 下的文件和目錄列表:c:rsyn rsync:/rsync-server-ip/test/drwxr-xr-x 0 2007/06/15 10:09:57 .drwxr-xr-x 0 2007/06/15 10:17:58 test1drwxr-
41、xr-x 0 2007/06/21 04:00:00 svntestdrwxr-xr-x 0 2007/06/21 02:00:33 tracdrwxr-xr-x 0 2007/06/21 03:00:27 wiki-rw-r-r- 2029823 2007/06/01 04:00:02 java.7z-rw-r-r- 361554934 2007/06/01 04:08:56 oracle.7z當(dāng)然還可以列出 module 下的某個目錄下的文件列表:c:rsyn rsync:/rsync-server-ip/test/wiki/ (注意要列出目錄 wiki 下的東西要以/結(jié)尾,不然它只會列出
42、 wiki 目錄自身)3.同步整個 module 到本地:c: rsync -v -t -l -r rsync:/rsync-server-ip/test/ .test注意:因為同步的時候需要計算服務(wù)器文件和本地文件之間的差異等,在同步文件的過程中 CPU 的占用可能會達(dá)到 100%,所以如果你是用它來做計劃任務(wù)式的備份和同步的話,最好選擇系統(tǒng)空閑的時候,比如早上4點(diǎn)。用rsync對網(wǎng)站進(jìn)行鏡像備份創(chuàng)建時間:2001-07-05文章屬性:原創(chuàng)文章來源: HYPERLINK / t _blank /文章提交: HYPERLINK /bbs/index.php?lang=cn&act=Profil
43、e&do=03&MID=2721 inburst (inburst_at_)用rsync對網(wǎng)站進(jìn)行鏡像備份by inburst HYPERLINK t _blank 對系統(tǒng)管理員來說,平時的工作重心應(yīng)該集中在維護(hù)系統(tǒng)正常運(yùn)轉(zhuǎn),能夠正常提供服務(wù)上,這里往往牽涉到一個數(shù)據(jù)備份的問題,在我所了解的情況中,有80%的系統(tǒng)管理員不是太關(guān)心自己服務(wù)器的安全性,但往往對備分鏡像的技術(shù)相當(dāng)感興趣,但由于商業(yè)產(chǎn)品的軟硬件價格都相當(dāng)高昂,因此往往會選擇自由軟件。這里準(zhǔn)備介紹的rsync就是這樣的軟件,它可以滿足絕大多數(shù)要求不是特別高的備份需求。一、特性簡介rsync是類unix系統(tǒng)下的數(shù)據(jù)鏡像備份工具,從軟件的命
44、名上就可以看出來了remote sync。它的特性如下:1、可以鏡像保存整個目錄樹和文件系統(tǒng)。2、可以很容易做到保持原來文件的權(quán)限、時間、軟硬鏈接等等。3、無須特殊權(quán)限即可安裝。4、優(yōu)化的流程,文件傳輸效率高。5、可以使用rcp、ssh等方式來傳輸文件,當(dāng)然也可以通過直接的socket連接。6、支持匿名傳輸。二、使用方法rsync的使用方法很簡單,我就舉自己使用的例子來說明吧。1、系統(tǒng)環(huán)境rsync支持大多數(shù)的類unix系統(tǒng),無論是Linux、Solaris還是BSD上都經(jīng)過了良好的測試。我的系統(tǒng)環(huán)境為:server: FreeBSD 4.3ip: 2client: Solaris 8ip:
45、37rsync 版本 2.4.6(可以從 HYPERLINK /rsync/ t _blank /rsync/獲得最新版本)2、配置server端的/etc/rsyncd.conf文件bash-2.03# cat /etc/rsyncd.confuid = nobody gid = nobody use chroot = no # 不使用chrootmax connections = 4 # 最大連接數(shù)為4pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.locklog file = /var/log/rsyncd.log# 日
46、志記錄文件inburst# 這里是認(rèn)證的模塊名,在client端需要指定path = /home/inburst/python/# 需要做鏡像的目錄comment = BACKUP CLIENT IS SOLARIS 8 E250 ignore errors# 可以忽略一些無關(guān)的IO錯誤read only = yes# 只讀list = no# 不允許列文件auth users = inburst# 認(rèn)證的用戶名,如果沒有這行,則表明是匿名secrets file = /etc/inburst.pas# 認(rèn)證文件名webpath = /usr/local/apache/htdocs/comme
47、nt = web server3、在server端生成一個密碼文件/etc/inburst.pasbash-2.03# cat /etc/inburst.pasinburst:hack出于安全目的,文件的屬性必需是只有屬主可讀。4、在server端將rsync以守護(hù)進(jìn)程形式啟動bash-2.03# rsync -daemon如果要在啟動時把服務(wù)起來,有幾種不同的方法,比如:a、加入inetd.conf編輯/etc/services,加入rsync 873/tcp,指定rsync的服務(wù)端口是873編加/etc/inetd.conf,加入rsyncstreamtcp nowaitroot/bin/
48、rsync rsync -daemonb、加入rc.local在各種操作系統(tǒng)中,rc文件存放位置不盡相同,可以修改使系統(tǒng)啟動時rsync -daemon加載進(jìn)去。5、從client端進(jìn)行測試下面這個命令行中-vzrtopg里的v是verbose,z是壓縮,r是recursive,topg都是保持文件原有屬性如屬主、時間的參數(shù)。-progress是指顯示出詳細(xì)的進(jìn)度情況,-delete是指如果服務(wù)器端刪除了這一文件,那么客戶端也相應(yīng)把文件刪除,保持真正的一致。后面的inburstip中,inburst是指定密碼文件中的用戶名,之后的:inburst這一inburst是模塊名,也就是在/etc/r
49、syncd.conf中自定義的名稱。最后的/tmp是備份到本地的目錄名。在這里面,還可以用-e ssh的參數(shù)建立起加密的連接??梢杂?password-file=/password/path/file來指定密碼文件,這樣就可以在腳本中使用而無需交互式地輸入驗證密碼了,這里需要注意的是這份密碼文件權(quán)限屬性要設(shè)得只有屬主可讀。bash-2.03# rsync -vzrtopg -progress -delete inburst2:inburst /tmp/Password: receiving file list . done./1785 (100%)1.py4086 (100%)2.py1068
50、0 (100%)a0 (100%)ip3956 (100%)./wrote 190 bytesread 5499 bytes758.53 bytes/sectotal size is 19507speedup is 3.436、創(chuàng)建更新腳本如果有比較復(fù)雜的工作,利用一些常見的腳本語言可以有幫助。比如:bash-2.03# cat /usr/local/bin/rsync.sh#!/bin/shDATE=date +%wrsync -vzrtopg -progress -delete inburst2:inburst /home/quack/backup/$DATE -password-file
51、=/etc/rsync.pass /var/log/rsync.$DATE7、修改/etc/crontab做好定時比如:bash-2.03# echo 154 * * 6 rootrsync.sh/etc/crontab三、FAQQ:如何通過ssh進(jìn)行rsync,而且無須輸入密碼?A:可以通過以下幾個步驟1. 通過ssh-keygen在server A上建立SSH keys,不要指定密碼,你會在/.ssh下看到identity和identity.pub文件 2. 在server B上的home目錄建立子目錄.ssh3. 將A的identity.pub拷貝到server B上4. 將identi
52、ty.pub加到user b/.ssh/authorized_keys5. 于是server A上的A用戶,可通過下面命令以用戶B ssh到server B上了e.g. ssh -l userB serverB這樣就使server A上的用戶A就可以ssh以用戶B的身份無需密碼登陸到server B上了。Q:如何通過在不危害安全的情況下通過防火墻使用rsync?A:解答如下:這通常有兩種情況,一種是服務(wù)器在防火墻內(nèi),一種是服務(wù)器在防火墻外。無論哪種情況,通常還是使用ssh,這時最好新建一個備份用戶,并且配置sshd僅允許這個用戶通過RSA認(rèn)證方式進(jìn)入。如果服務(wù)器在防火墻內(nèi),則最好限定客戶端的I
53、P地址,拒絕其它所有連接。如果客戶機(jī)在防火墻內(nèi),則可以簡單允許防火墻打開TCP端口22的ssh外發(fā)連接就ok了。Q:我能將更改過或者刪除的文件也備份上來嗎?A:當(dāng)然可以:你可以使用如:rsync -other -options -backupdir = ./backup-2000-2-13.這樣的命令來實現(xiàn)。這樣如果源文件:/path/to/some/file.c改變了,那么舊的文件就會被移到./backup-2000-2-13/path/to/some/file.c,這里這個目錄需要自己手工建立起來Q:我需要在防火墻上開放哪些端口以適應(yīng)rsync?A:視情況而定rsync可以直接通過873端
54、口的tcp連接傳文件,也可以通過22端口的ssh來進(jìn)行文件傳遞,但你也可以通過下列命令改變它的端口:rsync -port 8730 otherhost:或者rsync -e ssh -p 2002 otherhost:Q:我如何通過rsync只復(fù)制目錄結(jié)構(gòu),忽略掉文件呢?A:rsync -av -include */ -exclude * source-dir dest-dirQ:為什么我總會出現(xiàn)Read-only file system的錯誤呢?A:看看是否忘了設(shè)read only = no了Q:為什么我會出現(xiàn)ERROR: invalid gid的錯誤呢?A:rsync使用時默認(rèn)是用uid
55、=nobody;gid=nobody來運(yùn)行的,如果你的系統(tǒng)不存在nobody組的話,就會出現(xiàn)這樣的錯誤,可以試試gid = nogroup或者其它Q:綁定端口873失敗是怎么回事?A:如果你不是以root權(quán)限運(yùn)行這一守護(hù)進(jìn)程的話,因為1024端口以下是特權(quán)端口,會出現(xiàn)這樣的錯誤。你可以用-port參數(shù)來改變。Q:為什么我認(rèn)證失???A:從你的命令行看來:你用的是: bash$ rsync -a 13:test test Password: ERROR: auth failed on module test I dont understand this. Can somebody explain
56、as to how to acomplish this. All suggestions are welcome.應(yīng)該是沒有以你的用戶名登陸導(dǎo)致的問題,試試rsync -a max13:test test四、一些可借鑒的腳本這里這些腳本都是rsync網(wǎng)站上的例子:1、每隔七天將數(shù)據(jù)往中心服務(wù)器做增量備份#!/bin/sh# This script does personal backups to a rsync backup server. You will end up# with a 7 day rotating incremental backup. The incrementals w
57、ill go# into subdirectories named after the day of the week, and the current# full backup goes into a directory called current# tridge# directory to backupBDIR=/home/$USER# excludes file - this contains a wildcard pattern per line of files to excludeEXCLUDES=$HOME/cron/excludes# the name of the back
58、up machineBSERVER=owl# your password on the backup serverexport RSYNC_PASSWORD=XXXXXX#BACKUPDIR=date +%AOPTS=-force -ignore-errors -delete-excluded -exclude-from=$EXCLUDES -delete -backup -backup-dir=/$BACKUPDIR -aexport PATH=$PATH:/bin:/usr/bin:/usr/local/bin# the following line clears the last wee
59、ks incremental directory -d $HOME/emptydir | mkdir $HOME/emptydirrsync -delete -a $HOME/emptydir/ $BSERVER:$USER/$BACKUPDIR/rmdir $HOME/emptydir# now the actual transferrsync $OPTS $BDIR $BSERVER:$USER/current2、備份至一個空閑的硬盤#!/bin/shexport PATH=/usr/local/bin:/usr/bin:/binLIST=rootfs usr data data2for
60、d in $LIST; domount /backup/$drsync -ax -exclude fstab -delete /$d/ /backup/$d/umount /backup/$ddoneDAY=date +%Arsync -a -delete /usr/local/apache /data2/backups/$DAYrsync -a -delete /data/solid /data2/backups/$DAY3、對的cvs樹進(jìn)行鏡像#!/bin/bashcd /var/www/cvs/vger/PATH=/usr/local/bin:/usr/freeware/bin:/usr
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 生物化學(xué)(第4版)課件 第2章 核酸化學(xué)
- 氣候變化所致小島國損失損害補(bǔ)償責(zé)任問題研究
- 基于STSE教育理念的初中化學(xué)金屬和金屬材料的教學(xué)實踐研究
- 下雨天安全教育
- 關(guān)愛婦女心理健康:現(xiàn)狀與行動指南
- 頸椎間盤的護(hù)理課件
- 爆炸安全知識培訓(xùn)
- 人事勞資培訓(xùn)
- 項目管理人員安全教育培訓(xùn)
- 項目介紹課件模版
- 四年級數(shù)學(xué)上冊 (學(xué)霸自主提優(yōu)拔尖)第一單元《升和毫升》學(xué)霸提優(yōu)卷(有詳細(xì)答案)(蘇教版)
- 內(nèi)燃機(jī)噪音控制技術(shù)
- 2024年離婚協(xié)議書范文模范本兩個孩子
- 2024年北京中考地理試卷
- 杭四中分班考數(shù)學(xué)試題卷
- 會議系統(tǒng)施工施工方法及工藝要求
- 收割機(jī)買賣合同正規(guī)范本版
- 臨床成人ICU患者外周動脈導(dǎo)管管理要點(diǎn)
- 81.GJB 1112A-2004 軍用機(jī)場場道工程施工及驗收規(guī)范
- DZ∕T 0130-2006 地質(zhì)礦產(chǎn)實驗室測試質(zhì)量管理規(guī)范(正式版)
- 計劃開、竣工日期和施工進(jìn)度網(wǎng)絡(luò)圖112
評論
0/150
提交評論