因此我使用以下命令(当然以 root 身份)对我的 VPS 进行完整备份:
tar czvf 20120604.tar.gz /
一切似乎都很好,所有文件似乎都出现在列表中。存档的大小为 6 Gb,gunzipped 版本为 11 Gb,其中包括/home
,因为我在 VPS 上总共有 11 Gb 的数据。但当我尝试实际解压存档或使用 mc 或 WinRAR 打开它时,没有 /home 文件夹。并且 WinRAR 告诉20120604.tar.gz - TAR+GZIP archive, unpacked size 894 841 346 bytes
。这不可能是 WinRAR 的错误,因为当我输入时tar xzvf 20120604.tar.gz
,/home
文件夹也没有解压。
为什么/home
我的存档中缺少文件夹?我该怎么做才能将其包含在那里?
tar --version
输出以下内容:tar (GNU tar) 1.15.1
答案1
我高度怀疑 tar 备份中排除该/home
目录是由于以 root 身份执行(root 的主目录为/root/
)。浏览手册页(取自http://linux.die.net/man/1/tar)以下选项可能可能导致/解决/调试您的情况:
Main operation mode:
-C, --directory=DIR
change to directory DIR
-p, --preserve-permissions
extract information about file permissions (default for superuser)
-v, --verbose
verbosely list files processed
Operation modifiers:
-g, --listed-incremental=FILE
handle new GNU-format incremental backup
-G, --incremental
handle old GNU-format incremental backup
Handling of file attributes:
--group=NAME
force NAME as group for added files
--mode=CHANGES
force (symbolic) mode CHANGES for added files
--no-same-owner
extract files as yourself (default for ordinary users)
--no-same-permissions
apply the user's umask when extracting permissions from the archive (default for ordinary users)
--no-xattrs
Don't extract the user/root xattrs from the archive
--numeric-owner
always use numbers for user/group names
--owner=NAME
force NAME as owner for added files
-p, --preserve-permissions, --same-permissions
extract information about file permissions (default for superuser)
--same-owner
try extracting files with the same ownership as exists in the archive (default for superuser)
--xattrs
Save the user/root xattrs to the archive
Device selection and switching:
--force-local
archive file is local even if it has a colon
Archive format selection:
-H, --format=FORMAT
create archive of the given format--FORMAT is one of the following:
gnu, oldgnu, pax, posix, ustar, v7, --old-archive, --portability,
--pax-option=keyword[[:]=value][,keyword[[:]=value]]... , --posix,
-V, --label=TEXT
<see webpage/ man page for details>
Local file selection:
--add-file=FILE
add given FILE to the archive (useful if its name starts with a dash)
-C, --directory=DIR
change to directory DIR
-h, --dereference
follow symlinks; archive and dump the files they point to
--hard-dereference
follow hard links; archive and dump the files they refer to
-K, --starting-file=MEMBER-NAME
begin at member MEMBER-NAME in the archive
--one-file-system
stay in local file system when creating archive
-P, --absolute-names
don't strip leading '/'s from file names
--recursion
recurse into directories (default)
File name transformations:
--no-anchored
patterns match after any '/' (default for exclusion)
--no-ignore-case
case sensitive matching (default)
--no-wildcards
verbatim string matching
--no-wildcards-match-slash
wildcards do not match '/'
--wildcards
use wildcards (default)
--wildcards-match-slash
wildcards match '/' (default for exclusion)
Informative output:
--index-file=FILE
send verbose output to FILE
-l, --check-links
print a message if not all links are dumped
--show-defaults
show tar defaults
--show-omitted-dirs
when listing or extracting, list each directory that does not match search criteria
--show-transformed-names, --show-stored-names
show file or archive names after transformation
-v, --verbose
verbosely list files processed
-w, --interactive, --confirmation
ask for confirmation for every action
当然,要考虑的因素有很多,但如果不灵活和强大,Linux 命令就一文不值。我想,如果您使用具有有限文件系统结构的测试箱研究这些选项中的每一个,运行您打算使用的发行版,您将会找到要包含在脚本中的确切组合,以产生您想要的确切结果。
为了建立公共知识,您能否回复并提供实现所需行为的解决方案?