CONTENT 1. commands, important options, envir-var 2. Beispiele 3. man-page rsync see below ---------------------------------- ------------------------------------------------------------------------- ### --- ### --- ### --- Commands --- ### --- ### --- ### ------------------------------------------------------------------------- *** commands: rsync [Optionen] Quelle Ziel rsync -a Quelle/Ordner Ziel/ überträgt DIR Ordner "Ordner" incl. Inhalt ins Zielverzeichnis, erzeugt also noch den Ordner "Ordner", d.h ab dem letzten slash wird alles uebertragen rsync -a Quelle/Ordner/ Ziel/ überträgt nur Inhalt von Quelle/Ordner direkt ins Zielverzeichnis (wg. / ) rsync -rlptgoD home/huhn/* backup/ rsync -a --exclude=*.bak ~/artikel/* backup/ rsync -a --exclude=*.bak --exclude=*~ Quelle Ziel rsync -e ssh Quelle user@zielrechner:ziel/ rsync --progress --partial debian.iso transpluto:/scratch/debian/ *** important Options: -n startet das Programm lediglich einen Testlauf -r rekursiv -l includes links -L copy file instead of link -a = -rlptgoD recursiv, links, permissions, times, group, owner, devices, specials -oD only possible for admin, not for user !!! --exclude-from=Exclude-Datei alle Ausnahmen in eine Textdatei schreiben, jedes Suchmuster landet dabei in einer eigenen Zeile -e ssh die Dateien wandern verschlüsselt über das SSH-Protokoll hin und her --partial bricht der Transfer ab, wird das Übertragen der Daten zu einem späteren Zeitpunkt an der gleichen Stelle fortgesetzt Einen Nachteil hat die Option --partial dennoch: Verwenden Sie Rsync, um eine bereits vorhandene Datei zu aktualisieren und der Transfer bricht ab, verschwindet die Datei auf dem Zielrechner und wird durch den übertragenen Teil ersetzt. Sie umgehen dieses Problem, indem Sie zunächst von dem Original einen Hardlink anlegen: ln debian.iso debian_orig.iso. Bricht nun der Transfer ab, verschwindet nicht etwa das ISO-Image. Lediglich die partielle Datei bekommt einen neuen Namen, und das Original ist noch da. --progress zeigt den Fortschritt beim Übertragen --delete delete files that don't exist on sender, see below more delete-options --delete-excluded also delete excluded files on receiver -i, --itemize-changes output a change-summary for all updates *** Umgebungs-Variable: RSYNC_RSH=ssh Umgebungsvariable in BASH z.B. erspart die Eingabe des Parameter zum SSH-Verschlüsseln bei jedem Aufruf z.B. in die Bash-Konfigurationsdatei ~/.bashrc schreiben, mit source ~/.bashrc diese neu einlesen ------------------------------------------------------------------------- ### --- ### --- ### --- Beispiele --- ### --- ### --- ### ------------------------------------------------------------------------- ### rsnapshot: rsync_short_args<------>-a rsync_long_args>--numeric-ids --relative --delete-excluded --stats --log-file=/root/.rsnapshot/rsync-WD25-DATA.log ### rsync-dir: nice -n 15 rsync -a --recursive --progress --link-dest=$link_path --exclude-from=$excl --log-file=$log_path $src_path/ $dest_path$dir_dest | tee -a ### backup of NTFS-files with links # rsync-options: rltD # recursive, links, times, devices, specials # ! not: permissions, group, owner; not needed by saving NTFS-files nice -n 15 rsync -rltDv --recursive --progress --link-dest=$link_path --exclude-from=$excl_path --log-file=$log_path --files-from=$srcs $src_path $dest_path ### rsyncd: log-format default: operation, remote-host-name, remote IP, module name, auth user name, file name, length of file %o %h [%a] %m [%u] %f %l ### log format: see /media/sda6/gerd/DATA-Help/Sicherungen/rsync/rsync_log_format.txt ### exclude-files format: ( https://sites.google.com/site/rsync2u/home/rsync-tutorial/the-exclude-from-option ) For each name visited during the traversal of the source directory, rsync reads the list of patterns in the exclude file. rsync reads the list top down, and the first matching pattern is acted on: if it is a "-" pattern, then the name is excluded if it is a "+" pattern, then the name is included if no matching pattern is found, then the name is included If a directory name is excluded, that branch is skipped. If a directory name is included, the branch is traversed. The order of the patterns matters, as the following examples illustrate. ------------------------------------------------------------------------------ ### --- ### --- ### --- man-page rsync --- ### --- ### --- ### ------------------------------------------------------------------------------ ### man-page rsync rsync (11 Mar 2006) SYNOPSIS rsync [OPTION]... SRC [SRC]... DEST rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST rsync [OPTION]... SRC rsync [OPTION]... [USER@]HOST:SRC [DEST] rsync [OPTION]... [USER@]HOST::SRC [DEST] rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST] There are two different ways for rsync to contact a remote system: using a remote-shell program as the transport (such as ssh or rsh) or contacting an rsync daemon directly via TCP. The remote-shell transport is used whenever the source or destination path contains a single colon (:) separator after a host specification. Contacting an rsync daemon directly happens when the source or destination path contains a double colon (::) separator after a host specification, OR when an rsync:// URL is specified (see also the "USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION" section for an exception to this latter rule). Note that rsync must be installed on both the source and destination machines. rsync -t *.c foo:src/ rsync -avz foo:src/bar /data/tmp rsync -avz foo:src/bar/ /data/tmp gleicher Effekt, angehängter Backslash verhindert Anlegen des DIRs foo: rsync -av /src/foo /dest rsync -av /src/foo/ /dest/foo Note also that host and module references don't require a trailing slash to copy the contents of the default directory. For example, both of these copy the remote directory's contents into "/dest": rsync -av host: /dest rsync -av host::module /dest You can also use rsync in local-only mode, where both the source and destination don't have a ':' in the name. In this case it behaves like an improved copy command. rsync -avz src/bar /data/tmp Finally, you can list all the (listable) modules available from a particular rsync daemon by leaving off the module name: rsync somehost.mydomain.com:: Leerzeichen wie sie von der Ziel-Shell bearbeitet werden: rsync -av host:'file\ name\ with\ spaces' /dest mehrere DIRs: rsync -av host:'dir1/file1 dir2/file2' /dest --compare-dest=DIR This option instructs rsync to use DIR on the destination machine as an additional hierarchy to compare destination files against doing transfers (if the files are missing in the destination directory). If a file is found in DIR that is identical to the sender's file, the file will NOT be transferred to the destination directory. This is useful for creating a sparse backup of just files that have changed from an earlier backup. -copy-dest=DIR This option behaves like --compare-dest, but rsync will also copy unchanged files found in DIR to the destination directory using a local copy. This is useful for doing transfers to a new destination while leaving existing files intact, and then doing a flash-cutover when all files have been successfully transferred. --link-dest=DIR unchanged files are hard linked from DIR to the destination directory, if DIR is a relative path, it is relative to the destination directory: rsync -av --link-dest=$PWD/prior_dir host:src_dir/ new_dir/ multiple link-dest=DIR possible. rsyncbackup.vbs: rsync -av[R][c][n] --link-dest="recentBackupFolder.Path" --exclude "aExcludeFile" toCygwinPath(aSourceFolder) toCygwinPath(strDestinationFolder) -R, --relative use relative path names -c, --checksum skip based on checksum, not mod-time & size -n, --dry-run show what would have been transferred --link-dest=DIR hardlink to files in DIR when unchanged Häufige Optionen: -r sichert Unterverzeichnisse -l sichert symbol. Link -p sichert Rechte -t sichert Zeiten -g sichert Gruppe -o sichert Dateieigentümer (kann nur root verwenden) -D sichert Device-Eigenschaften (kann nur root verwenden) -a = -rlptgoD --exclude=*.bak Dateien vom Synchronisieren ausklammern oder --exclude-from=Exclude-Datei --exclude=.* Punkt-Dateien / -Verzeichnisse nicht sichern -e ssh Dateien werden verschlüsselt über SSH-Protokoll verschickt --partial bei Transfer-Abbruch: später an der selben Stelle fortsetzen --progress zeigt den Fortschritt an --delete gelöschte Dateien werden auch in der Sicherung gelöscht (hat nur Auswirkungen bei mehreren Sicherungsläufen pro Tag) -u, --update skip files that are newer on the receiver Beispiele: @: rsync -e ssh Quelle user@zielrechner:ziel/. # wenn user verschieden: angeben! rsync -a --exclude=*.bak --exclude=*~ Quelle Ziel $ rsync --progress --partial debian.iso transpluto:/scratch/debian/ Hinweis: Das Script überprüft nicht, ob im Zielverzeichnis genügend freier Speicher vorhanden ist. Fehler bei den Eingabeparametern fängt das Script nicht ab. Die Tagesordner werden aus Gründen der Sicherheit nicht automatisch gelöscht. Da jeweils nur geänderte Dateien gesichert werden hält sich die Datenmenge jedoch in Grenzen. ---------------------------------------------------------- CONNECTING TO AN RSYNC DAEMON (see: man rsyncd.conf) It is also possible to use rsync without a remote shell as the transport. In this case you will directly connect to a remote rsync daemon, typically using TCP port 873. (This obviously requires the daemon to be running on the remote system, so refer to the STARTING AN RSYNC DAEMON TO ACCEPT CONNECTIONS section below for information on that.) Using rsync in this way is the same as using it with a remote shell except that: * you either use a double colon :: instead of a single colon to separate the hostname from the path, or you use an rsync:// URL. * the first word of the "path" is actually a module name. * the remote daemon may print a message of the day when you connect. * if you specify no path name on the remote daemon then the list of accessible paths on the daemon will be shown. * if you specify no local destination then a listing of the specified files on the remote daemon is provided. * you must not specify the --rsh (-e) option. An example that copies all the files in a remote module named "src": rsync -av host::src /dest Some modules on the remote daemon may require authentication. If so, you will receive a password prompt when you connect. You can avoid the password prompt by setting the environment variable RSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be useful when scripting rsync. rsync -av -e "ssh -l ssh-user" rsync-user@host::module /dest The "ssh-user" will be used at the ssh level; the "rsync-user" will be used to log-in to the "module". -------------------------------- OPTIONS SUMMARY Here is a short summary of the options available in rsync. Please refer to the detailed description below for a complete description. -v, --verbose increase verbosity -q, --quiet suppress non-error messages -c, --checksum skip based on checksum, not mod-time & size -a, --archive archive mode; same as -rlptgoD (no -H) --no-OPTION turn off an implied OPTION (e.g. --no-D) -r, --recursive recurse into directories -R, --relative use relative path names --no-implied-dirs don't send implied dirs with --relative -b, --backup make backups (see --suffix & --backup-dir) --backup-dir=DIR make backups into hierarchy based in DIR --suffix=SUFFIX backup suffix (default ~ w/o --backup-dir) -u, --update skip files that are newer on the receiver --inplace update destination files in-place --append append data onto shorter files -d, --dirs transfer directories without recursing -l, --links copy symlinks as symlinks -L, --copy-links transform symlink into referent file/dir --copy-unsafe-links only "unsafe" symlinks are transformed --safe-links ignore symlinks that point outside the tree -k, --copy-dirlinks transform symlink to dir into referent dir -K, --keep-dirlinks treat symlinked dir on receiver as dir -H, --hard-links preserve hard links -p, --perms preserve permissions -E, --executability preserve executability --chmod=CHMOD change destination permissions -o, --owner preserve owner (super-user only) -g, --group preserve group --devices preserve device files (super-user only) --specials preserve special files -D same as --devices --specials -t, --times preserve times -O, --omit-dir-times omit directories when preserving times --super receiver attempts super-user activities -S, --sparse handle sparse files efficiently -n, --dry-run show what would have been transferred -W, --whole-file copy files whole (without rsync algorithm) -x, --one-file-system don't cross filesystem boundaries -B, --block-size=SIZE force a fixed checksum block-size -e, --rsh=COMMAND specify the remote shell to use --rsync-path=PROGRAM specify the rsync to run on remote machine --existing ignore non-existing files on receiving side --ignore-existing ignore files that already exist on receiver --remove-sent-files sent files/symlinks are removed from sender --del an alias for --delete-during --delete delete files that don't exist on sender --delete-before receiver deletes before transfer (default) --delete-during receiver deletes during xfer, not before --delete-after receiver deletes after transfer, not before --delete-excluded also delete excluded files on receiver --ignore-errors delete even if there are I/O errors --force force deletion of dirs even if not empty --max-delete=NUM don't delete more than NUM files --max-size=SIZE don't transfer any file larger than SIZE --min-size=SIZE don't transfer any file smaller than SIZE --partial keep partially transferred files --partial-dir=DIR put a partially transferred file into DIR --delay-updates put all updated files into place at end -m, --prune-empty-dirs prune empty directory chains from file-list --numeric-ids don't map uid/gid values by user/group name --timeout=TIME set I/O timeout in seconds -I, --ignore-times don't skip files that match size and time --size-only skip files that match in size --modify-window=NUM compare mod-times with reduced accuracy -T, --temp-dir=DIR create temporary files in directory DIR -y, --fuzzy find similar file for basis if no dest file --compare-dest=DIR also compare received files relative to DIR --copy-dest=DIR ... and include copies of unchanged files --link-dest=DIR hardlink to files in DIR when unchanged -z, --compress compress file data during the transfer --compress-level=NUM explicitly set compression level -C, --cvs-exclude auto-ignore files in the same way CVS does -f, --filter=RULE add a file-filtering RULE -F same as --filter='dir-merge /.rsync-filter' repeated: --filter='- .rsync-filter' --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 -0, --from0 all *from/filter files are delimited by 0s --address=ADDRESS bind address for outgoing socket to daemon --port=PORT specify double-colon alternate port number --sockopts=OPTIONS specify custom TCP options --blocking-io use blocking I/O for the remote shell --stats give some file-transfer stats -8, --8-bit-output leave high-bit chars unescaped in output -h, --human-readable output numbers in a human-readable format --progress show progress during transfer -P same as --partial --progress -i, --itemize-changes output a change-summary for all updates --log-format=FORMAT output filenames using the specified format --password-file=FILE read password from FILE --list-only list the files instead of copying them --bwlimit=KBPS limit I/O bandwidth; KBytes per second --write-batch=FILE write a batched update to FILE --only-write-batch=FILE like --write-batch but w/o updating dest --read-batch=FILE read a batched update from FILE --protocol=NUM force an older protocol version to be used --checksum-seed=NUM set block/file checksum seed (advanced) -4, --ipv4 prefer IPv4 -6, --ipv6 prefer IPv6 --version print version number (-h) --help show this help (see below for -h comment) Rsync can also be run as a daemon, in which case the following options are accepted: --daemon run as an rsync daemon --address=ADDRESS bind to the specified address --bwlimit=KBPS limit I/O bandwidth; KBytes per second --config=FILE specify alternate rsyncd.conf file --no-detach do not detach from the parent --port=PORT listen on alternate port number --sockopts=OPTIONS specify custom TCP options -v, --verbose increase verbosity -4, --ipv4 prefer IPv4 -6, --ipv6 prefer IPv6 -h, --help show this help (if used after --daemon) ******** --files-from=FILE Using this option allows you to specify the exact list of files to transfer (as read from the specified FILE or - for standard input). It also tweaks the default behavior of rsync to make transferring just the specified files and directories easier: * The --relative (-R) option is implied, which preserves the path information that is specified for each item in the file (use --no-relative or --no-R if you want to turn that off). * The --dirs (-d) option is implied, which will create directories specified in the list on the destination rather than noisily skipping them (use --no-dirs or --no-d if you want to turn that off). * The --archive (-a) option's behavior does not imply --recursive (-r), so specify it explicitly, if you want it. * These side-effects change the default state of rsync, so the position of the --files-from option on the command-line has no bearing on how other options are parsed (e.g. -a works the same before or after --files-from, as does --no-R and all other options). The filenames that are read from the FILE are all relative to the source dir -- any leading slashes are removed and no ".." references are allowed to go higher than the source dir. For example, take this command: rsync -a --files-from=/tmp/foo /usr remote:/backup If /tmp/foo contains the string "bin" (or even "/bin"), the /usr/bin directory will be created as /backup/bin on the remote host. If it contains "bin/" (note the trailing slash), the immediate contents of the directory would also be sent (without needing to be explicitly mentioned in the file -- this began in version 2.6.4). In both cases, if the -r option was enabled, that dir's entire hierarchy would also be transferred (keep in mind that -r needs to be specified explicitly with --files-from, since it is not implied by -a). Also note that the effect of the (enabled by default) --relative option is to duplicate only the path info that is read from the file -- it does not force the duplication of the source-spec path (/usr in this case). In addition, the --files-from file can be read from the remote host instead of the local host if you specify a "host:" in front of the file (the host must match one end of the transfer). As a short-cut, you can specify just a prefix of ":" to mean "use the remote end of the transfer". For example: rsync -a --files-from=:/path/file-list src:/ /tmp/copy This would copy all the files specified in the /path/file-list file that was located on the remote "src" host.