在另一个磁盘中归档文件 linux

Archiving file in another disk linux

如何将某个文件存档到 linux 上的另一个硬盘?

例如,我想归档存在于我的密码中且超过两年的文件,我在 bash 脚本中写道:

if [ $file -mtime +730 ]; then

例如,现在我不知道要添加哪个命令才能将文件存档在 /dev/sdb1 中。

提前感谢您的帮助!

I want to archive the files that exist my pwd and are older than two years

包括两个步骤:

  • 查找两年前的所有文件
  • 从第一步归档文件

要“查找”文件,请使用 find。程序 find 采用参数 -mtime。命令 [ 不采用 -mtime 参数。

我认为“存档”只是 cp。要存档到 光盘 ,您首先必须格式化该光盘以存储 文件 ,然后您可以将文件复制到在该光盘上创建的文件系统中.

总的来说,它会有所作为:

 # First format and mount
 # Note - it will erase all the files
 sudo mkfs /dev/sdb1
 sudo mount /dev/sdb1 /mnt/somedir
 # then copy
 find . -type f -mtime +730 -print0 |
 xargs -0 cp -a -t /mnt/somedir --parents

这使用 GNU 工具和特定于 GNU cp-t--parents 选项 - 请参阅手册。但是无论如何,您最有可能使用 rsync 并研究 rdiff-backup 和其他更好的工具来进行“归档”。