优化空间 rdiff-backup

Ale*_*eri 2 linux rdiff-backup

大家好,在 etc/crontab 中使用 Ubuntu10 进入我的服务器 linux 我有这个:

0 0 * * * user rdiff-backup -v9 user@111.111.111.111::/var/www/ /mnt/server1/www
0 1 * * * user rdiff-backup -v9 user@222.222.222.222::/var/www/ /mnt/server2/www
0 2 * * * user rdiff-backup -v9 user@333.333.333.333::/var/www/ /mnt/server3/www
Run Code Online (Sandbox Code Playgroud)

例如,服务器有一个 2Tb 的硬盘,我的备份大约占用了 1Tb。
我每天晚上都做备份,现在如果这个备份工作一年或更长时间,我的硬盘空间我认为会减少,因为 rdiff-backup 制作了更改文件的历史记录。
是否可以限制到我的 crontab 中来限制历史记录和维护控制的硬盘空间?类似于:“30 版本后取消最旧的”。
可以将其放入我的文件 crontab 中吗?

Ken*_*ert 5

由于您的 cron 作业每天都在运行,并且您希望保留 30 个版本,因此这与删除所有 30 天之前的增量备份相同。

这可以通过 rdiff-backup 使用--remove-older-than选项指定30D1M. 您不能--remove-older-than在单个命令中与备份或恢复数据结合使用。您需要在 crontab 中添加行。

另一个警告是--remove-older-than拒绝同时删除多个增量,除非您指定该--force选项。您可以尝试手动运行一次--force,然后让 cron 作业每天删除一个增量。如果出于某种原因(例如服务器关闭)未运行 cron 作业,这可能会导致问题。我会--force在 cron 作业中包含该选项。

您的新 crontab 可能如下所示:

0 0 * * * user rdiff-backup -v9 user@111.111.111.111::/var/www/ /mnt/server1/www
0 1 * * * user rdiff-backup -v9 user@222.222.222.222::/var/www/ /mnt/server2/www
0 2 * * * user rdiff-backup -v9 user@333.333.333.333::/var/www/ /mnt/server3/www
0 3 * * * user rdiff-backup -v9 --remove-older-than 1M --force /mnt/server1/www
20 3 * * * user rdiff-backup -v9 --remove-older-than 1M --force /mnt/server2/www
40 3 * * * user rdiff-backup -v9 --remove-older-than 1M --force /mnt/server3/www
Run Code Online (Sandbox Code Playgroud)

在创建新备份之前是否删除旧增量或在什么时间运行哪个作业是您应该决定的事情。

需要明确的是:只有恢复到 30 天前的增量备份状态所需的信息才会被删除,而不是现在仍然存在或在最近的增量备份中的旧数据。


有关该--remove-older-than选项的更多信息,您可以阅读手册页

--remove-older-than time_spec
          Remove the incremental backup  information  in  the  destination
          directory  that  has  been  around  longer  than the given time.
          time_spec can be either an absolute time, like "2002-01-04",  or
          a  time  interval.   The time interval is an integer followed by
          the character s, m, h, D, W, M, or Y, indicating  seconds,  min-
          utes,  hours,  days,  weeks, months, or years respectively, or a
          number of these concatenated.  For example, 32m  means  32  min-
          utes,  and 3W2D10h7s means 3 weeks, 2 days, 10 hours, and 7 sec-
          onds.  In this context, a month means 30 days,  a  year  is  365
          days, and a day is always 86400 seconds.

          rdiff-backup  cannot remove-older-than and back up or restore in
          a single session.  In order  to  both  backup  a  directory  and
          remove old files in it, you must run rdiff-backup twice.

          By  default,  rdiff-backup will only delete information from one
          session at a time.  To remove two or more sessions at  the  same
          time,  supply  the --force option (rdiff-backup will tell you if
          --force is required).

          Note that snapshots of deleted files are covered by this  opera-
          tion.  Thus if you deleted a file two weeks ago, backed up imme-
          diately afterwards, and then  ran  rdiff-backup  with  --remove-
          older-than  10D  today,  no  trace  of  that  file would remain.
          Finally, file selection options such as --include and  --exclude
          don't affect --remove-older-than.
Run Code Online (Sandbox Code Playgroud)