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)