linux-(Inotify-tools&rsync build real-time backup system)

Source: Internet
Author: User
Tags inotify file permissions rsync

inotifywait command

The Mac is: Fswatch,fsevents-tools.

1. Command format:

inotifywait [parameters] [events] [TargetDir]

2. Command function:

Normally inotifywait hangs there until the file/directory has an event to cause concern, it exits and outputs the location where the event occurred, the name of the event, and the file that caused the event (output when the event occurred on the directory).

3. Command parameters:

The most common options for inotifywait are two:

-R indicates recursive monitoring of events occurring in subdirectories

-e Specifies the list of events to monitor.

For a backup system, you only need to monitor modify, create, and delete three of events.

4. Usage examples:

Inotifywait-r-E modify,create,delete/tmp

Represents three events for monitoring file modification, file creation, and file deletion in the/tmp directory and its subdirectories.

rsync Command 1. Command format:

rsync [parameters] [original directory] [target directory]

2. Command function:

Rsync is a fast incremental backup tool. It has several features that make it ideal for use as a backup tool:

    • Incremental backup, only the modified content is transferred

    • Can be decompressed in real-time during transmission, reducing bandwidth consumption

    • Can keep the original file permissions, events, soft and hard links

    • Native replication supported, remote replication supported

3. Command parameters:

-A represents archive mode, which backs up all content in the directory (including content in subdirectories), and maintains soft links, file attributes, file modification events, file owner and host information, and synchronizes character/block devices and special files named Sockets and FIFO.

-V indicates the details of the output backup

-Z indicates compression on transfer

–delete Delete files that are not in the source directory in the destination directory

4. Usage examples:

Rsync-avz--delete Src/foo:/data

src/means to back up the SRC directory of all the content, note that the last/not removed, otherwise the SRC directory itself back to the past

Foo:/data indicates that the backup destination is the/data/directory under the Foo host

Build a real-time backup system

Use a while dead loop to integrate two of tools.

#!/bin/Bashif[[$#-ne2]]; Then    Cat<<Eofusage $ (basename$0) Source_dir [host:]dest_direof exit0fiSource_dir=$1Dest_dir=$2 while : Doinotifywait-r-e modify,create,delete ${source_dir} && rsync-avz ${source_dir}/${dest_dir}--Delete Done

linux-(Inotify-tools&rsync build real-time backup system)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.