文件夹监控
-
场景:由于考虑到网站安全的需要,所以有必要对站点所在的文件夹进行实时监控,以保证第一时间能发现木马和注入。
-
方法:inotify,这个需要linux的内核是2.6.13以上,通关uname 查看确认内核,并通过以下命令确认inotify是否已经启用。
<!-- lang: shell -->
ls -l /proc/sys/fs/inotify/ -rw-r--r-- 1 root root 0 Mar 8 09:36 max_queued_events -rw-r--r-- 1 root root 0 Mar 8 09:36 max_user_instances -rw-r--r-- 1 root root 0 Mar 8 09:36 max_user_watches
-
incron是与cron类似,但它是用来监控文件变化的。下载个最新版本,安装好后,根据配置方法:<path> <mask> <command>,输入命令:
<!-- lang: shell -->
incrontab -e
/var/mail IN_CLOSE_WRITE abc $@/$#
具体参数见:incron
文件夹备份
-
场景:文件夹备份首先会考虑对文件夹进行压缩。方法很多,考虑到PHP在命令行下运行也很方便,就找了个PHP压缩类
-
PclZip, 官网
-
调用方法:
<!-- lang: php -->
<?php // Include the PclZip library require_once('pclzip.lib.php'); // Set the arhive filename $archive = new PclZip('backup/archive.zip'); // Set the dir to archive $v_dir = dirname(getcwd()); // or dirname(__FILE__); $v_remove = $v_dir; // Create the archive $v_list = $archive->create($v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove); if ($v_list == 0) { die("Error : ".$archive->errorInfo(true)); }
?> 如果不加PCLZIP_OPT_REMOVE_PATH, 那么压缩包内的文件带着原来的路径,非常深。