文件监控与cab压缩包制作 cabarc语法

来源:互联网 发布:人工智能的利与弊论文 编辑:程序博客网 时间:2024/05/23 01:20
File Share文件夹备份策略及监控机制(2)

共享文件夹的监控:

如果经常出现重要文件丢失情况,我们需要弄清楚,到底谁删除了文件,以追究责任,这就涉及到了文件的监控情形。

通常涉及到操作是恶意删除或修改文件,造成文件丢失或异常。

监控的设置如下:

由于我们通过Security log记录获取操作信息,所以第一步,我们需要将需要监控的文件夹添加到审核audit信息,鼠标右键“属性”---》Security---》auditing




点击add按钮,我们可以设定对某一个人或某工作组进行监控,如果需要对所有人进行监控,直接输入“everyone”,然后选择对哪种操作进行监控





设置完毕后,操作会自动监控此共享文件夹,一旦发现有人执行的监控动作,就会记录在Security log中,其中包括了事件编号,时间,操作人,动作等等。

由于log文件有容量大小限制,建议大小128M,到达限制后,会覆盖老的记录,我们需要定时将security log备份出来,那我们可以通过脚本进行备份:

第一步将完整的系统日志备份到某一个特定文件夹中,并命名

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _

& strComputer & "\root\cimv2")



Set colLogFiles = objWMIService._execQuery _

("_select* from Win32_NTEventLogFile")



For Each objLogfile in colLogFiles

If objLogFile.FileSize > 0 Then

strBackupLog = objLogFile.BackupEventLog("E:\Script\Temp\" & objLogFile.LogFileName & ".evt")

objLogFile.ClearEventLog()

End If

Next

第二步 获取当前时间

Set CURRDATE=%TEMP%\CURRDATE.TMP

Set CURRTIME=%TEMP%\CURRTIME.TMP

DATE /T > %CURRDATE%

TIME /T > %CURRTIME%

Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "

For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j

Set PARSEARG="eol=; tokens=1,2,3* delims=:, "

For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k

第三步, 调用系统打包工具cabarc.exe,将所以的log文件压缩成CAB文件,然后复制特定文件夹,删除临时文件

cabarc N \\192.168.1.2\e$\AllEventLogs\EventLogs_%computername%_%YYYYMMDD%_%HHMM%.cab E:\Script\Temp\*.*

del /Q E:\Script\Temp\*.*

另存为eventlog.bat文件,

第五步,新建计划任务,调用eventlog.bat

完成!

这样出现问题后,估计大体日期,直接到AllEventLogs文件夹,打开对应日期日志备份就可以查看具体操作了。

补充:Cabarc.exe 工具的应用介绍:

它是微软提供的一个高级系统工具,可以从微软官方网站中下载.

具体的介绍如下:

这个命令行工具允许用户去创建,查询,解压缩CAB包;但是它不能向已存在的CAB中添加新的文件,WinRAR则可以。

这个工具没有图形用户界面,必须通过命令行进行使用

此工具适用的环境是XP, Server2003

CABarc命令语法:

Microsoft (R) Cabinet Tool - Version 5.2.3790.0

Copyright (c) Microsoft Corporation. All rights reserved..



Usage: CABARC [options] command cabfile [@list] [files] [dest_dir]



Commands:

L List contents of cabinet (e.g. cabarc l test.cab)

N Create new cabinet (e.g. cabarc n test.cab *.c app.mak *.h)

X Extract file(s) from cabinet (e.g. cabarc x test.cab foo*.c)



Options:

-c Confirm files to be operated on

-o When extracting, overwrite without asking for confirmation

-m Set compression type [LZX:<15..21>|MSZIP|NONE], (default is MSZIP)

-p Preserve path names (absolute paths not allowed)

-P Strip specified prefix from files when added

-r Recurse into subdirectories when adding files (see -p also)

-s Reserve space in cabinet for signing (e.g. -s 6144 reserves 6K bytes)

-i Set cabinet set ID when creating cabinets (default is 0)

-d Set diskette size (default is no limit/single CAB)



Notes

-----

When creating a cabinet, the plus sign (+) may be used as a filename

to force a folder boundary; e.g. cabarc n test.cab *.c test.h + *.bmp



When extracting files to disk, the <dest_dir>, if provided, must end in

a backslash; e.g. cabarc x test.cab bar*.cpp *.h d:\test\



The -P (strip prefix) option can be used to strip out path information

e.g. cabarc -r -p -P myproj\ a test.cab myproj\balloon\*.*

The -P option can be used multiple times to strip out multiple paths



When creating cabinet sets using -d, the cabinet name should contain

a single '*'_character where the cabinet number will be inserted.

1. 获取CAB文件包中的文件列表
打开cmd命令,输入cabarc l FileName.cab
其中FileName CAB包的文件名

2. 创建CAB包创建
cabarc [/m {lzx:Compression|mszip|none}] [/p] [/P Pathname] [/r] [/s] [/I SetID] n NewCabFileName[*].cab FileNameOrPattern [FileNameOrPattern [...]]

Parameters

/m {lzx: Compression |mszip|none}

设置压缩类型,如果没有指定,默认压缩类型为MSZIP



Value
Description

LZX:Compression
Uses LZX compression. Valid Compression values are 15 to 21.

MSZIP
Uses MSZip format.

NONE
Uses no compression.



/p

Preserves path names. Absolute paths are not allowed.

指定路径名称,绝对路径是不允许的

/P Pathname

Strips the specified Pathname from files when they are added to the CAB file.

指定需要加入CAB压缩包的文件所在的文件夹路径

注意/P 这个参数可以使用多次,用于将多个路径的文件一次性加入CAB包

/r

Recurses into subdirectories when adding files.

以递归的方式,将路径下的子文件夹也加入cab包

/s

Reserves space in the CAB file for signing. For example, /s 6144 reserves 6K bytes.

/i SetID

Sets the CAB set ID when creating CAB files. The default set ID is 0.

设定CAB的ID好,默认ID是0

NewCabFileName[*] .cab

指定待创建的cab.包的名称

Note

· When using the /d parameter, the NewCabFileName should contain a single "*"_character where the cabinet number will be inserted.

3. 解压缩文件Extracts files from a CAB file.

Syntax

cabarc [/c] [/o] x CabFileNameFileNameOrPattern [FileNameOrPattern [...]] [Pathname]

Parameters

/c

Confirms which files will be extracted.

/o

Specifies that existing files with the same name as those being extracted will be overwritten without asking for confirmation.

CabFileName .cab

指定需要解压缩的cab包的名称及路径,例如:

c:\test\mycab.cab

FileNameOrPattern

指定需要被解压缩的文件类型,例如:

myfile.ini mfiles.*

Pathname

指定解压缩后的文件存放的路径,

例如 c:\myfiles\; 如果没有指定路径,系统默认解压缩到当前路径下


实例:

cabarc l c:\builds\support.cab

cabarc x c:\builds\support.cab *.dll

The .dll files will be extracted to the current directory.

cabarc n test1.cab *.dll

cabarc n D:\doc\Bill\Script\备份日志\1.cab D:\doc\Bill\Script\备份日志\*.xlsx

原创粉丝点击