linux - 根据文件年龄压缩完整文件结构的脚本

标签 linux backup gzip tar

好吧,我有一个运行 CentOS 的 Web 服务器在工作,它仅在内部托管几个网站。这是我们的开发服务器,因此有很多 [阅读大量] 旧垃圾网站等等。

我试图详细说明一个命令,该命令可以找到超过 6 个月未修改的文件,将它们全部分组到一个 tarball 中,然后删除它们。到目前为止,我已经尝试过许多不同类型的带参数的查找命令等等。我们的结构看起来像这样

/var/www/joomla/用户名/fileshere/temp /var/www/用户名/fileshere

所以我尝试了以下几行:

find /var/www -mtime -900 ! -mtime -180 | xargs tar -cf test4.tar

当预期结果超过 50 GB 时,只生成 10MB 的 tar。

我尝试使用 gzip 代替,但我最终压缩了我的整个服务器,因此无法使用,不得不转移整个文件系统并重新安装一个完整的新服务器以及很多麻烦和麻烦......你明白了。所以我想找到一个完美的命令,它不会炸毁我们的服务器,但会找到超过 6 个月未修改的所有文件和目录。

最佳答案

小心使用 ctime。

  1. ctime 与对 inode 所做的更改(更改权限、所有者等)相关

  2. 上次访问文件的时间(检查您的文件系统是否使用 noatime 或 relatime 选项,在这种情况下,atime 选项可能无法按预期方式工作)

  3. 最后一次修改文件中数据的时间。

根据您要执行的操作,mtime 选项可能是您的最佳选择。

此外,您应该检查 print0 选项。从人身上找到:

-print0
          True;  print  the full file name on the standard output, followed by a null character (instead of the newline character that -print uses).  This allows file names that contain newlines or
          other types of white space to be correctly interpreted by programs that process the find output.  This option corresponds to the -0 option of xargs.

我不知道你想做什么,但这个命令可能对你有用:

find /var/www -mtime +180 -print0 | xargs -0 tar -czf example.tar.gz

关于linux - 根据文件年龄压缩完整文件结构的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19387471/

相关文章:

linux - gzip 文件夹的总大小

javascript - 我运行应用程序时出现 Angular2 GZIP 问题

bash - IO::Uncompress::Gunzip 在 "original"gzipped 文件内的第一个 "concatenated"gzipped 文件后停止

linux - 面试题: Are you familiar with linux?

linux - 如何在 Linux 中对 grep 的管道输出进行子字符串化?

linux - Go exec.CommandContext 在上下文超时后不会被终止

mysql - 备份mysql集群数据库的最佳方法

emacs - 自动备份服务器上的 emacs 文件编辑

mysql - 索引失败。回滚所有更改。 (Solr 数据导入)

linux - Bash 输出仅限于回显