我的 TAR 脚本怎么了?

tro*_*roy 6 gzip tar

这可能在 StackExchange 上做得更好,但我使用 Ubuntu 作为我的文件服务器。

因此,我正在尝试使用tar并且gzip仅备份文件服务器上最近 6 个月的更改,但它不起作用。它没有gzip任何作用,它将 tar 文件放在与脚本相同的目录中(不是我想要的),并将文件名更改为 tar 字符串的一部分。

这是脚本:

#!/bin/bash


tod=$(date +%F_%H%M%S)
echo "start"
echo $tod

echo "testing tar, only the last 6 months"
tar -cvf--newer-mtime=08-11-2013 /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar /homedepot/yellowsolo/xz/official/official /homedepot/yellowsolo/xz/home/home

echo "now zipping"
gzip /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar.gz

echo $tod
echo "done"
exit
Run Code Online (Sandbox Code Playgroud)

提前致谢

Wil*_*ilf 7

尝试:

#!/bin/bash
tod=$(date +%F_%H%M%S)
echo "Start"
echo $tod

echo "testing tar, only the last 6 months"
tar --newer-mtime=20130811 -cvzf /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar /homedepot/yellowsolo/xz/official/official /homedepot/yellowsolo/xz/home/home

echo "Done"
exit
Run Code Online (Sandbox Code Playgroud)

我已经清除了 tar 命令中的错误 - 您需要f在文件名之前有选项,并通过 gzip(z选项)过滤它。