how to use commands cronlog and rsync

rsync

远程的同步工具,同步远程数据到另一台机器,可以保持原数据的属性(权限,所有者,timestap等等。
以server-client模式运行,rsync程序既可以做服务端,也可以做client的cmdline端。
服务模式运行在服务端:

        rsync --daemon --config=/etc/rsyncd.conf

客户端在shell命令行下输入rysnc 命令来执行同步,在客户端和服务端进行同步数据。

在客户端运行:

        rsync -aSvH --password-file=/etc/sery.pass root@remoteServer::data /home/

把远程的/etc/rsyncd.conf中的item【data】同步到本地的/home/下。

rysnc服务端配置:
[root@mailsvr ~] # cat /etc/rsyncd.conf
uid = root   #root用户访问                     
gid = root   #root组用户访问                  
use chroot = no     #不能使用chroot    
max connections = 9 #最大连接数         
list = yes   #允许列出文件清单                 
pid file = /var/run/rsyncd.pid                  
lock file = /var/run/rsync.lock                   
log file = /var/log/rsyncd.log                                
hosts allow = 192.168.1.2   #只允许这个主机访问
                                                                                 
[data]     #发布项

path = /home/data/     #发布的路径
ignore errors             
read only = yes   #只读
auth users = root   #认证用户为root
secrets file = /etc/sery.pass    #密码文件

mannual:

NAME
       rsync — a fast, versatile, remote (and local) file-copying tool

SYNOPSIS
       Local: rsync [OPTION...] SRC... [DEST]

       Access via remote shell:
         Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
         Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

       Access via rsync daemon:
         Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
               rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
         Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
               rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

       Usages with just one SRC arg and no DEST arg will list the source files
       instead of copying.

DESCRIPTION
       Rsync is a fast and extraordinarily versatile file copying tool.   It
       can copy locally, to/from another host over any remote shell, or
       to/from a remote rsync daemon. It offers a large number of options
       that control every aspect of its behavior and permit very flexible
       specification of the set of files to be copied. It is famous for its
       delta-transfer algorithm, which reduces the amount of data sent over
       the network by sending only the differences between the source files
       and the existing files in the destination. Rsync is widely used for
       backups and mirroring and as an improved copy command for everyday use.

       Rsync finds files that need to be transferred using a “quick check”
       algorithm (by default) that looks for files that have changed in size
       or in last-modified time.   Any changes in the other   preserved
       attributes (as requested by options) are made on the destination file
       directly when the quick check indicates that the file's data does not
       need to be updated.


-------------------------------------------------------------------------------------------------------

cronolog

从stdin读取日志,根据日志的timestamp进行切割(切成文件),输出到适合的文件。

日志切割以模板为基准,如"%Y/%m/%d/access.log" 表示每天时间段的日志被放在这个位置。

通过选项 -d 制定切割周期,如每30minutes 切割一次。

mannual:

NAME
       cronolog - write log messages to log files named according to a template

SYNOPSIS
       cronolog [OPTION]... template

DESCRIPTION
       cronolog is a simple program that reads log messages from its input and writes them to a set of output files, the names of which are constructed using template and
       the current date and time. The template uses the same format specifiers as the Unix date(1) command (which are the same as the standard C strftime library function).

       Before writing a message cronolog checks the time to see whether the current log file is still valid and if not it closes the current file, expands the template
       using the current date and time to generate a new file name, opens the new file (creating missing directories on the path of the new log file as needed unless the
       program is compiled with -DDONT_CREATE_SUBDIRS) and calculates the time at which the new file will become invalid.

       cronolog is intended to be used in conjunction with a Web server, such as Apache to split the access log into daily or monthly logs. For example the Apache config‐
       uration directives:

               TransferLog "|/www/sbin/cronolog /www/logs/%Y/%m/%d/access.log"
               ErrorLog    "|/www/sbin/cronolog /www/logs/%Y/%m/%d/errors.log"

       would instruct Apache to pipe its access and error log messages into separate copies of cronolog, which would create new log files each day in a directory hierarchy
       structured by date, i.e. on 31 December 1996 messages would be written to

               /www/logs/1996/12/31/access.log
               /www/logs/1996/12/31/errors.log

       after midnight the files

               /www/logs/1997/01/01/access.log
               /www/logs/1997/01/01/errors.log

       would be used, with the directories 1997, 1997/01 and 1997/01/01 being created if they did not already exist. (Note that prior to version 1.2 Apache did not allow
       a program to be specified as the argument of the ErrorLog directive.)

OPTIONS

       -p PERIOD

        --period=PERIOD
              specifies the period explicitly as an optional digit string followed by one of units: seconds, minutes, hours, days, weeks or months. The count cannot be
              greater than the number of units in the next larger unit, i.e. you cannot specify "120 minutes", and for seconds, minutes and hours the count must be a fac‐
              tor of the next higher unit, i.e you can specify 1, 2, 3, 4, 5, 6, 10, 15, 20 or 30 minutes but not say 7 minutes.

猜你喜欢

转载自wuchengyi.iteye.com/blog/815268
今日推荐