日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux实时备份,51CTO博客-专业IT技术博客创作平台-技术成就梦想

發(fā)布時間:2025/4/16 linux 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux实时备份,51CTO博客-专业IT技术博客创作平台-技术成就梦想 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

rsync缺點(diǎn)/不足:

1.rsync在同步數(shù)據(jù)時,需要掃描所有文件后進(jìn)行比對,進(jìn)行差量傳輸。如果文件數(shù)量達(dá)到了百萬甚至千萬量級,掃描所有文件將是非常耗時的,并且正在發(fā)生變化的往往是其中很少的一部分,這是非常低效的方式。

2.rsync不能實(shí)時的去監(jiān)測、同步數(shù)據(jù),雖然它可以通過linux守護(hù)進(jìn)程的方式進(jìn)行觸發(fā)同步,但是兩次觸發(fā)動作一定會有時間差,這樣就導(dǎo)致了服務(wù)端和客戶端數(shù)據(jù)可能出現(xiàn)不一致,無法在應(yīng)用故障時完全的恢復(fù)數(shù)據(jù)。linux內(nèi)核從2.6.13起,加入了inotify支持,通過inotify可以監(jiān)控文件系統(tǒng)中添加、刪除、修改、移動等各種事件,利用這個內(nèi)核接口,第三方軟件就可以監(jiān)控文件系統(tǒng)下文件的各種變化情況,而inotify-tools正是實(shí)施監(jiān)控的軟件。

在使用rsync首次全量同步后,結(jié)合inotify對源目錄進(jìn)行實(shí)時監(jiān)控,只有有文件變動或新文件產(chǎn)生,就會立刻同步到目標(biāo)目錄下,非常高效使用!

inotify :創(chuàng)建一個文件描述符,附加一個或多個監(jiān)視器(一個監(jiān)視器是一個路徑和一組事件),然后用read方法從描述符獲取事件,read并不會用完整個周期,它是事件發(fā)生之前是被阻塞的。

文件描述符:linux內(nèi)核為了更優(yōu)秀的管理被打開的文件創(chuàng)建的索引,是一個非負(fù)整數(shù)。用于指代被打開的文件,所有執(zhí)行io的操作 系統(tǒng)調(diào)用都是通過文件描述符。0表示標(biāo)準(zhǔn)輸入,1表示標(biāo)準(zhǔn)輸出,2表示標(biāo)準(zhǔn)錯誤輸出。

查看linux內(nèi)核版本

需要看當(dāng)前l(fā)inux是否支持inotify[root@Rsync-139?~]#?uname?-a

Linux?Rsync-139?2.6.32-431.el6.x86_64?#1?SMP?Fri?Nov?22?03:15:09?UTC?2013?x86_64?x86_64?x86_64?GNU/Linux

[root@Rsync-139?~]#?ls?-lsart?/proc/sys

sys/???????????sysrq-trigger??sysvipc/

[root@Rsync-139?~]#?ls?-lsart?/proc/sys/fs/inotify/

總用量?0

0?dr-xr-xr-x?0?root?root?0?11月??5?15:31?..

0?dr-xr-xr-x?0?root?root?0?11月??6?16:12?.

0?-rw-r--r--?1?root?root?0?11月??6?16:12?max_user_watches

0?-rw-r--r--?1?root?root?0?11月??6?16:12?max_user_instances

0?-rw-r--r--?1?root?root?0?11月??6?16:12?max_queued_events

安裝[root@Rsync-139?~]#?tar?-zxvf?inotify-tools-3.14.tar.gz?-C?/usr/local/src/

[root@Rsync-139?~]#?./configrue?--prefix=/usr/local/inotify

[root@Rsync-139?~]#?make?&&make?install

需要加環(huán)境變量vim?/etc/profile

最低行加:/usr/local/inotify/bin/

重新加載配置文件.?/etc/profile?或者

source?/etc/profile

查看幫助信息

inotifywait --help[root@WebA-136?script]#?inotifywait?--help

inotifywait?3.14

Wait?for?a?particular?event?on?a?file?or?set?of?files.

Usage:?inotifywait?[?options?]?file1?[?file2?]?[?file3?]?[?...?]

Options:可用選項

-h|--help???????Show?this?help?text.

@?????????Exclude?the?specified?file?from?being?watched.

--exclude?

Exclude?all?events?on?files?matching?the

extended?regular?expression?.

--excludei?

Like?--exclude?but?case?insensitive.

-m|--monitor????Keep?listening?for?events?forever.??Without

this?option,?inotifywait?will?exit?after?one

event?is?received.

-d|--daemon?????Same?as?--monitor,?except?run?in?the?background

logging?events?to?a?file?specified?by?--outfile.

Implies?--syslog.

-r|--recursive??Watch?directories?recursively.

--fromfile?

Read?files?to?watch?from??or?`-'?for?stdin.

-o|--outfile?

Print?events?to??rather?than?stdout.

-s|--syslog?????Send?errors?to?syslog?rather?than?stderr.

-q|--quiet??????Print?less?(only?print?events).

-qq?????????????Print?nothing?(not?even?events).

--format???Print?using?a?specified?printf-like?format

string;?read?the?man?page?for?more?details.

--timefmt??strftime-compatible?format?string?for?use?with

%T?in?--format?string.

-c|--csv????????Print?events?in?CSV?format.

-t|--timeout?

When?listening?for?a?single?event,?time?out?after

waiting?for?an?event?for??seconds.

If??is?0,?inotifywait?will?never?time?out.

-e|--event??[?-e|--event??...?]

Listen?for?specific?event(s).??If?omitted,?all?events?are

listened?for.

Exit?status:可以監(jiān)控的事件

0??-??An?event?you?asked?to?watch?for?was?received.

1??-??An?event?you?did?not?ask?to?watch?for?was?received

(usually?delete_self?or?unmount),?or?some?error?occurred.

2??-??The?--timeout?option?was?given?and?no?events?occurred

in?the?specified?interval?of?time.

Events:

access??????????file?or?directory?contents?were?read

modify??????????file?or?directory?contents?were?written

attrib??????????file?or?directory?attributes?changed

close_write?????file?or?directory?closed,?after?being?opened?in

writeable?mode

close_nowrite???file?or?directory?closed,?after?being?opened?in

read-only?mode

close???????????file?or?directory?closed,?regardless?of?read/write?mode

open????????????file?or?directory?opened

moved_to????????file?or?directory?moved?to?watched?directory

moved_from??????file?or?directory?moved?from?watched?directory

move????????????file?or?directory?moved?to?or?from?watched?directory

create??????????file?or?directory?created?within?watched?directory

delete??????????file?or?directory?deleted?within?watched?directory

delete_self?????file?or?directory?was?deleted

unmount?????????file?system?containing?file?or?directory?unmounted

常用

-r 遞歸(目錄)

-m 永久監(jiān)聽

-d 后臺運(yùn)行

-q 靜默,只輸出較少的信息

編寫腳本進(jìn)行實(shí)時備份vim?inotify.sh

inotifywait?-mrq?--timefmt?'%d%m%y?%H:%M'?--format?'%T?%w%f%e'?-e?close_write,modify,delete,create,attrib,move?/var/log/?|while?read?file

do

rsync?-az?--delete-before?/var/log/?rsync_WebA@192.168.146.139::WebA/?--password-file=/etc/WebA.pass

done

./inotify?&放入后臺執(zhí)行即可

注:

rsync error: some files/attrs were not transferred (see previous errors) (code 23) at

main.c(1505)是因?yàn)樵谕降臅r候,源目錄下有軟鏈接文件!

rsync同步軟鏈接文件,應(yīng)該加參數(shù)-l

總結(jié)

以上是生活随笔為你收集整理的linux实时备份,51CTO博客-专业IT技术博客创作平台-技术成就梦想的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。