我正在构建一个脚本来备份我的 Linux 中的文件和目录。 这些备份存储在 map 存档中。
现在我在我的源代码中使用了一个特定的目录,但是我有例如
包含这些目录的 input.txt:
/Downloads
/etc/var
或者还有特定的文件
/etc/log/test.txt
使用/Downloads 或/etc/var 还必须备份这些目录的子目录。例如。/Downloads 有 3 个其他目录/dir1、/dir2、/dir3 这些也需要存档。
我如何使用该文件 input.txt 作为源? 在整个 input.txt 文件中,我必须制作 1 个存档。
#!/bin/sh
source="/Downloads"
archive="example.tgz"
dest="Archive"
path="input.txt"
tar czf $dest/$archive $source
ls $dest
#this is how i read my file
while read line
do
echo $line
done < $path
最佳答案
使用 tar 创建存档 -T
选项可用于从输入文件中获取文件。
输入.txt:
/Downloads
/etc/var
/etc/log/test.txt
脚本:
#!/bin/sh
archive="example.tgz"
dest="Archive"
path="input.txt"
tar czf $dest/$archive -T $path
关于linux - 使用输入列表备份的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34592283/