rsync practice

.gitignore 中的文件不复制

--filter=':- .gitignore'

会删除

--delete

windows下的c盘路径

/cygdrive/c/Users/

在linux上 将 windows 上的name@ip:/cygdrive/c/Users/name/Desktop/what 目录, 复制到本地的/here/your/Documents/dest

rsync -rlptzv --filter=':- .gitignore' --progress --delete name@ip:/cygdrive/c/Users/name/Desktop/what /here/your/Documents/dest

from /c/a to /f/test

rsync --dry-run --delete-during --verbose --progress --archive --recursive --compress --log-file=/f/log.txt /c/a /f/test

rsync  --delete-during --verbose --progress --archive --recursive --compress --log-file=/f/log.txt /c/a /f/test

option

--no-OPTION              turn off an implied OPTION (e.g. --no-D)

log

--verbose, -v            increase verbosity
--itemize-changes, -i    output a change-summary for all updates
--quiet, -q              suppress non-error messages
--list-only              list the files instead of copying them
--log-file=FILE          log what we're doing to the specified FILE
--log-file-format=FMT    log updates using the specified FMT
The default FORMAT used if --log-file is specified and this option is not is '%i %n%L'.

The default log format is "%o %h [%a] %m (%u) %f %l", and a "%t [%p] " is always prefixed when using the "log file" parameter. (A perl script that will summarize this default log format is included in the rsync source code distribution in the "support" subdirectory: rsyncstats.)

The single-character escapes that are understood are as follows:

%a the remote IP address (only available for a daemon)
%b the number of bytes actually transferred
%B the permission bits of the file (e.g. rwxrwxrwt)
%c the total size of the block checksums received for the basis file (only when sending)
%C the full-file checksum if it is known for the file. For older rsync protocols/versions, the checksum was salted, and is thus not a useful value (and is not displayed when that is the case). For the checksum to output for a file, either the --checksum option must be in-effect or the file must have been transferred without a salted checksum being used. See the --checksum-choice option for a way to choose the algorithm.
%f the filename (long form on sender; no trailing "/")
%G the gid of the file (decimal) or "DEFAULT"
%h the remote host name (only available for a daemon)
%i an itemized list of what is being updated
%l the length of the file in bytes
%L the string " -> SYMLINK", " => HARDLINK", or "" (where SYMLINK or HARDLINK is a filename)
%m the module name
%M the last-modified time of the file
%n the filename (short form; trailing "/" on dir)
%o the operation, which is "send", "recv", or "del." (the latter includes the trailing period)
%p the process ID of this rsync session
%P the module path
%t the current date time
%u the authenticated username or an empty string
%U the uid of the file (decimal)

dry run

--dry-run, -n            perform a trial run with no changes made

selection

--recursive, -r          recurse into directories
--exclude=PATTERN        exclude files matching PATTERN
--exclude-from=FILE      read exclude patterns from FILE
--include=PATTERN        don't exclude files matching PATTERN
--include-from=FILE      read include patterns from FILE
--files-from=FILE        read list of source-file names from FILE

compress

--compress, -z           compress file data during the transfer

delete

--delete                 delete extraneous files from dest dirs
--delete-before          receiver deletes before xfer, not during
--delete-during          receiver deletes during the transfer
--delete-delay           find deletions during, delete after
--delete-after           receiver deletes after transfer, not during

process

--progress               show progress during transfer

copy mode

--archive, -a            archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
--recursive, -r          recurse into directories
--links, -l              copy symlinks as symlinks
--perms, -p              preserve permissions
--times, -t              preserve modification times
--group, -g              preserve group
--owner, -o              preserve owner (super-user only)
-D                       same as --devices --specials
--devices                preserve device files (super-user only)
--specials               preserve special files

--acls, -A               preserve ACLs (implies --perms)
--xattrs, -X             preserve extended attributes
--atimes, -U             preserve access (use) times
--crtimes, -N            preserve create times (newness)
--hard-links, -H         preserve hard links

checksum

--checksum, -c           skip based on checksum, not mod-time & size

--checksum-choice=STR, --cc=STR
This option overrides the checksum algorithms. If one algorithm name is specified,
it is used for both the transfer checksums and (assuming --checksum is specified) the pre-transfer checksums.
If two comma-separated names are supplied, the first name affects the transfer checksums,
and the second name affects the pre-transfer checksums (-c).

The checksum options that you may be able to use are:

auto (the default automatic choice)
xxh128
xxh3
xxh64 (aka xxhash)
md5
md4
sha1
none
Run rsync --version to see the default checksum list compiled into your version (which may differ from the list above).

Bandwidth throttling

--bwlimit=RATE

This option allows you to specify the maximum transfer rate for the data sent over the socket,
specified in units per second.
The RATE value can be suffixed with a string to indicate a size multiplier,
and may be a fractional value (e.g. --bwlimit=1.5m).

If no suffix is specified, the value will be assumed to be in units of 1024 bytes (as if "K" or "KiB" had been appended).
See the --max-size option for a description of all the available suffixes.
A value of 0 specifies no limit.

https://rsync.samba.org/documentation.html

Ignore

-C, --cvs-exclude           auto-ignore files in the same way CVS does

files listed in a `$HOME/.cvsignore` are added to the list and any
files listed in the `CVSIGNORE` environment variable (all cvsignore names are delimited by whitespace)

if the pattern ends with a / then it will only match a directory, not a regular file, symlink, or device.
a oq*cq matches any path component, but it stops at slashes
use '**' to match anything, including slashes.
a oq?cq matches any character except a slash (/).
--filter=':- .gitignore
--exclude=".git"
--exclude 'node_modules'
--exclude='*.out'
--exclude=.ccache --exclude=build
--exclude={.ccache,build}
--exclude=/folder/{one,two}/*
--exclude={'file1.txt','dir1/*','dir2'}
--exclude={'*.jpg','*.mp4'}
--exclude='*.'{jpg,mp4}

When having multiple directories and/or files to exclude, make a text file and use the --exclude-from switch.
Make a file called exclude_me.txt and in it list your exclusions. Example (/home/ben/exclude_me.txt):

.ccache
build
.java
.gvfs
.xsession-errors

Then your rsync would look something like this:

rsync -arv --exclude-from='/home/ben/exclude_me.txt' /home/ben /media/ben/thumbdrive/

This is some information on filter rules that may help:

  • /dir/ means exclude the root folder /dir, It's important to note that root folder means the root of the transfer not the root directory.
  • /dir/* means get the root folder /dir but not the contents
  • dir/ means exclude any folder anywhere where the name contains dir/, Examples excluded: /dir/, /usr/share/directory/, /var/spool/dir/
  • /var/spool/lpd/cf means skip files that start with cf within any folder within /var/spool/lpd

https://askubuntu.com/questions/320458/how-to-exclude-multiple-directories-with-rsync

posted @ 2023-03-31 19:12  fndefbwefsowpvqfx  阅读(17)  评论(0编辑  收藏  举报