Il primo argomento è il SOURCE il secondo è il DESTINATION(come "cp"). Per chiarezza usare sempre gli argomenti in forma estesa.

local to remote (PUSH)

mirror criptato su ssh

rsync  -v --dry-run --archive --cvs-exclude --compress --force --delete --progress --no-perms --no-owner --no-group --exclude-from=exclude.txt --rsh "ssh -p22" /path/local user@host:/path/remote
 
 
rsync  -v --archive --cvs-exclude --compress --force --delete --stats --rsh "ssh -p22" /path/local/ user@host:/path/remote/

remote to local (PULL)

Copy file from a remote server to a local computer

 
# remote copy
rsync --archive --compress /path/local user@host:/path/remote/
 
rsync -v --rsh ssh user@host:/path/to/local/file.txt /path/to/remote/file.txt
// copia in locale le pagine del wiki remoto
$cmd "scp -r user@host:/path/remote/* /path/local";

$cmd "rsync -v --archive --rsh ssh user@srver:/path/remote/* /path/local";
passthru($cmd);

sync local dirs

# note the trailing slash
rsync --archive /local_path_A/ /local_path_B
 
# local copy
rsync -v --archive --one-file-system --executability --delete --ignore-errors /path/local /path/remote

scp

per scaricare files semplice senza algoritmo diff e compressione

$ldir dirname(__FILE__);
$cmd "scp -r user@host:/path/local/* /path/local";

windows

  • GUI port di server e client DeltaCopy
  • porable cwRync and get the following files: rsync.exe, cygwin1.dll and cygz.dll

synchronizes the directory "F: / my files" on the USB key to the folder :c:\usb"

  • size-only: because the modified date of files in Windows is not always reliable.
  • --chmod=ugo=rwX because otherwise you cannot read the files in the destination (NTFS rights locked without this option)
rsync -r -v --size-only --chmod=ugo=rwX "/cygdrive/f/my file" "/cygdrive/c/usb"
 
// working windows:
rsync --dry-run -v --archive --cvs-exclude --compress --stats --progress -h --force --delete --rsh "ssh" /cygdrive/c/x username@host:/var/x

ATTENZIONE: On windows, your exclude-from or include-from file must be in Unix format (newlines rather that cr/lf).

PHP wrapper

// test for exe in place
$has_rsync = !empty( trim(`which rsync`) );
$has_sshpass = !empty( trim(`which sshpass`) );

// @see project seed
// --no-perms non settare permessi ai file remoti
// --omit-dir-times  will avoid it trying to set modification times on directories.
$cmd ="$rsync_cmd $cmd_dry_run -v --archive --cvs-exclude --compress  --checksum --stats --progress -h --force --delete $exclude --no-perms --omit-dir-times --rsh \"$ssh_cmd\" $local_path $user@$host:$remote_path";

automatizzare l'immissione della pasword:

$remote_shell "/usr/bin/sshpass -p $pwd ssh -p22";
$cmd_remote_shell "--rsh \"$remote_shell\"";// equivale a -e
$cmd "rsync -v --archive --cvs-exclude --compress --delete --force
--stats --progress --human-readable
--checksum --no-perms --no-owner --no-group
"
;
$cmd .= $cmd_remote_shell $local_path$user@$host:$remote_path";
echo 
$cmd;