因此,我使用以下命令(當然是以 root 身分)對我的 VPS 進行完整備份:
tar czvf 20120604.tar.gz /
一切似乎都很好,所有文件似乎都出現在列表中。存檔的大小為 6 Gb,壓縮版本為 11 Gb,其中包括/home
,因為我在 VPS 上總共有 11 Gb 的資料。但是當我嘗試實際解壓縮存檔或使用 mc 或 WinRAR 打開它時,沒有 /home 資料夾。 WinRAR 告訴我們20120604.tar.gz - TAR+GZIP archive, unpacked size 894 841 346 bytes
。這不可能是 WinRAR 的 bug,因為當我輸入 時tar xzvf 20120604.tar.gz
,/home
資料夾也沒有解壓縮。
為什麼/home
我的存檔中缺少資料夾?我該怎麼做才能將其包含在那裡?
tar --version
輸出以下內容:tar (GNU tar) 1.15.1
答案1
/home
我高度懷疑tar 備份中目錄的排除是作為 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 指令如果不靈活、強大就什麼都不是。我想,如果您使用具有有限檔案系統結構的測試盒來研究這些選項中的每一個,運行您打算使用的發行版,您將找到包含在腳本中的確切組合,以產生您想要的確切結果。
為了建立公共知識,您能否回發提供您想要的行為的解決方案?