分类:
2008-10-13 17:03:14
$ tar cvjf - * | ssh user@remote "(cd /desired/path; tar xjf -)"
----------------------------------------------------------------------------# tar cvzf - /wwwdata | ssh ssh root@192.168.1.201 "dd of=/backup/wwwdata.tar.gz"
# tar cvzf - /wwwdata | ssh ssh root@192.168.1.201 "cat > /dev/nst0"
# tar cvzf - /wwwdata | ssh ssh root@192.168.1.201 $(mt -f /dev/nst0 rewind; cat > /dev/nst0)$
# cd /
tar的用法from tar --help - [
# ssh root@192.168.1.201 "cat /backup/wwwdata.tar.gz" | tar zxvf -
-----------------------------------------------------------------------------
[/url]
]
Tag:
[url=http://wuhaixing.blogbus.com/s5339/]linux_Xray
GNU `tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive.
GNU 'tar'是一个打包程序,它可以把很多文件输入到一个管道或磁盘存储文件中,也可从包文件中还原出单个的文件。
Usage: tar [OPTION]... [FILE]...
用法:tar [命令选项]... [文件]...
Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.
例子:
tar -cf archive.tar foo bar #将foo和bar打包到archive.tar包中。
tar -tvf archive.tar #列出archive.tar包中文件的详细信息
tar -xf archive.tar #释放出archive.tar中的所有文件
If a long option shows an argument as mandatory, then it is mandatory
for the equivalent short option also. Similarly for optional arguments.
大多数命令选项有长和短两种形式,无论是必须的还是可选的选项,长短两种形式是一样的。
命令选项主要可以控制如下内容:
主要的操作模式、操作修正、文件属性的处理、设备的选择和切换、设备块、包文件格式的选择、本地文件的选择、提示信息的输出
Main operation mode:
-t, --list list the contents of an archive
-x, --extract, --get extract files from an archive
-c, --create create a new archive
-d, --diff, --compare find differences between archive and file system
-r, --append append files to the end of an archive
-u, --update only append files newer than copy in archive
-A, --catenate append tar files to an archive
--concatenate same as -A
--delete delete from the archive (not on mag tapes!)
主要的操作模式:
-t, --list 列出包文件中的内容
-x, --extract, --get 从包中释放文件
-c, --create 创建一个新的包
-d, --diff, --compare 找出包和文件系统的不同
-r, --append 将文件追加到包文件的最后
-u, --update 仅把有变化的文件重新加入到包中
-A, --catenate 把tar文件加入到包中
--concatenate 同 -A
--delete 从包中删除 (not on mag tapes!)
Operation modifiers:
-W, --verify attempt to verify the archive after writing it
--remove-files remove files after adding them to the archive
-k, --keep-old-files don't replace existing files when extracting
--overwrite overwrite existing files when extracting
--overwrite-dir overwrite directory metadata when extracting
-U, --unlink-first remove each file prior to extracting over it
--recursive-unlink empty hierarchies prior to extracting directory
-S, --sparse handle sparse files efficiently
-O, --to-stdout extract files to standard output
-G, --incremental handle old GNU-format incremental backup
-g, --listed-incremental=FILE
handle new GNU-format incremental backup
--ignore-failed-read do not exit with nonzero on unreadable files
操作修正选项:
-W, --verify 对包文件进行写操作后尝试验证
--remove-files 把文件加入到包中后从磁盘中删除
-k, --keep-old-files 释放的时候不要覆盖掉已存在的文件
--overwrite 释放的时候覆盖掉已存在的文件
--overwrite-dir 释放的时候覆盖掉路径的元数据
-U, --unlink-first 释放文件前先删除原有文件
--recursive-unlink 释放路径之前先清空原路径
-S, --sparse handle sparse files efficiently
-O, --to-stdout 将文件释放到标准输出
-G, --incremental 处理旧的GNU-format 增量备份
-g, --listed-incremental=FILE
处理新的GNU-format 增量备份
--ignore-failed-read do not exit with nonzero on unreadable files
Handling of file attributes:
--owner=NAME force NAME as owner for added files
--group=NAME force NAME as group for added files
--mode=CHANGES force (symbolic) mode CHANGES for added files
--atime-preserve don't change access times on dumped files
-m, --modification-time don't extract file modified time
--same-owner try extracting files with the same ownership
--no-same-owner extract files as yourself
--numeric-owner always use numbers for user/group names
-p, --same-permissions extract permissions information
--no-same-permissions do not extract permissions information
--preserve-permissions same as -p
-s, --same-order sort names to extract to match archive
--preserve-order same as -s
--preserve same as both -p and -s
对文件属性的处理:
--owner=NAME 强制指定 NAME 作为所添加的文件的所有者
--group=NAME 强制指定 NAME 作为所添加的文件的组
--mode=CHANGES 强制指定 (symbolic) 所添加文件的权限模式为 CHANGES
--atime-preserve 不要改变释放(dumped)文件的访问时间
-m, --modification-time 不要释放文件的修改时间
--same-owner 尝试以文件原有的所有者信息释放它
--no-same-owner 将文件作为你的文件释放
--numeric-owner always use numbers for user/group names
-p, --same-permissions extract permissions information
--no-same-permissions do not extract permissions information
--preserve-permissions same as -p
-s, --same-order sort names to extract to match archive
--preserve-order same as -s
--preserve same as both -p and -s
Device selection and switching:
-f, --file=ARCHIVE use archive file or device ARCHIVE
--force-local archive file is local even if has a colon
--rsh-command=COMMAND use remote COMMAND instead of rsh
-[0-7][lmh] specify drive and density
-M, --multi-volume create/list/extract multi-volume archive
-L, --tape-length=NUM change tape after writing NUM x 1024 bytes
-F, --info-script=FILE run script at end of each tape (implies -M)
--new-volume-script=FILE same as -F FILE
--volno-file=FILE use/update the volume number in FILE
Device blocking:
-b, --blocking-factor=BLOCKS BLOCKS x 512 bytes per record
--record-size=SIZE SIZE bytes per record, multiple of 512
-i, --ignore-zeros ignore zeroed blocks in archive (means EOF)
-B, --read-full-records reblock as we read (for 4.2BSD pipes)
Archive format selection:
-V, --label=NAME create archive with volume name NAME
PATTERN at list/extract time, a globbing PATTERN
-o, --old-archive, --portability write a V7 format archive
--posix write a POSIX format archive
-j, --bzip2 filter the archive through bzip2
-z, --gzip, --ungzip filter the archive through gzip
-Z, --compress, --uncompress filter the archive through compress
--use-compress-program=PROG filter through PROG (must accept -d)
Local file selection:
-C, --directory=DIR change to directory DIR
-T, --files-from=NAME get names to extract or create from file NAME
--null -T reads null-terminated names, disable -C
--exclude=PATTERN exclude files, given as a PATTERN
-X, --exclude-from=FILE exclude patterns listed in FILE
--anchored exclude patterns match file name start (default)
--no-anchored exclude patterns match after any /
--ignore-case exclusion ignores case
--no-ignore-case exclusion is case sensitive (default)
--wildcards exclude patterns use wildcards (default)
--no-wildcards exclude patterns are plain strings
--wildcards-match-slash exclude pattern wildcards match '/' (default)
--no-wildcards-match-slash exclude pattern wildcards do not match '/'
-P, --absolute-names don't strip leading `/'s from file names
-h, --dereference dump instead the files symlinks point to
--no-recursion avoid descending automatically in directories
-l, --one-file-system stay in local file system when creating archive
-K, --starting-file=NAME begin at file NAME in the archive
-N, --newer=DATE only store files newer than DATE
--newer-mtime=DATE compare date and time when data changed only
--after-date=DATE same as -N
--backup[=CONTROL] backup before removal, choose version control
--suffix=SUFFIX backup before removal, override usual suffix
Informative output:
--help print this help, then exit
--version print tar program version number, then exit
-v, --verbose verbosely list files processed
--checkpoint print directory names while reading the archive
--totals print total bytes written while creating archive
-R, --block-number show block number within archive with each message
-w, --interactive ask for confirmation for every action
--confirmation same as -w
The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control may be set with --backup or VERSION_CONTROL, values are:
t, numbered make numbered backups
nil, existing numbered if numbered backups exist, simple otherwise
never, simple always make simple backups
GNU tar cannot read nor produce `--posix' archives. If POSIXLY_CORRECT
is set in the environment, GNU extensions are disallowed with `--posix'.
Support for POSIX is only partially implemented, don't count on it yet.
ARCHIVE may be FILE, HOST:FILE or
[email=USER@HOST:FILE]USER@HOST:FILE[/email]
; DATE may be a textual date
or a file name starting with `/' or `.', in which case the file's date is used.
*This* `tar' defaults to `-f- -b20'.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/45990/showart_426168.html
--------------------------------------------------------------------
三、更多参数
以三大常见操作为序说明。
1、备份