🖥️rsync
➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the rsync command with important options and switches using examples.
5 minute read
▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁
# ██████╗ ███████╗██╗ ██╗███╗ ██╗ ██████╗
# ██╔══██╗██╔════╝╚██╗ ██╔╝████╗ ██║██╔════╝
# ██████╔╝███████╗ ╚████╔╝ ██╔██╗ ██║██║
# ██╔══██╗╚════██║ ╚██╔╝ ██║╚██╗██║██║
# ██║ ██║███████║ ██║ ██║ ╚████║╚██████╗
# ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝
# To copy files from remote to local, maintaining file properties and sym-links (-a), zipping for faster transfer (-z), verbose (-v).
rsync -avz host:file1 :file1 /dest/
rsync -avz /source host:/dest
# Copy files using checksum (-c) rather than time to detect if the file has changed. (Useful for validating backups).
rsync -avc /source/ /dest/
# Copy contents of /src/foo to destination:
# This command will create /dest/foo if it does not already exist
rsync -auv /src/foo /dest
# Explicitly copy /src/foo to /dest/foo
rsync -auv /src/foo/ /dest/foo
#==============================#
# CMD rsync
#==============================##==============================#
rsync --bwlimit=200 src dest
# Do an rsync and limit the bandwidth used to about 200 KBytes/sec. Useful on shared or slow links.
rsync -aqzH (public mirror that supports rsync).???::CentOS /path/to/locate/mirror
# Build a private mirror of the public mirror.
rsync -a -delete empty/ foo/
# Apparently according to testing, this is the fastest way to delete millions of small files. Apparently the fastest way to delete millions of small files. http://bit.ly/1fnUVIl
# Backup pictures while on travel, but exclude larger RAW images for now.
rsync -zav -e ssh . user@remote:europe-backup/ --exclude='*.CR2'
# Examples for Rsync
########################
# It is secure & faster than scp & can also be used in place of scp command to copy files/directories to remote host.
# Syntax for using rsync is
rsync options source destination
# Rsync’s main function, on the other hand is basically to synchronize files/directories either on local host or on remote host. Rsync initially copies whole directory & then copies newly added files (differential backup) rather than copying whole directory again.
rsync –azvh /datafile [email protected]:/home/susan
# here, option r is archive mode which allows copying of files recursively along with their file permissions, symbolic links etc,
# Second option r is used to compress file data,
# third option h will provide human readable outputs,
# and option v will provide debugging information which can help in diagnosing a problem related to connection, authentication etc,
# Also, we can mention alocal location like /home/dan in place of [email protected]:/home/susan
# Use rsync instead of cp to get a progress indicator when copying large files
rsync --progress largefile.gz somewhere/else/
# Explanation: Although rsync is famous for synchronizing files across machines, it also works locally on the same machine. And although the cp command does not have progress indicator, which can be annoying when copying large files, but rsync does have it, so there you go.
# Limitations: When copying directories be careful that the meaning of a trailing slash when specifying directories can be slightly different from cp.
rsync -azvh – -progress [email protected]:/home/susan /datafile
# above example will let us synchronize a directory from remote location to local host directory & –progress will show us the progress of file/directory transfer.
rsync –avzhe ssh /datafile [email protected]:/home/susan
# this example will let us use rsync over ssh and option –e here is used to define a protocol , which is this case is ssh.
rsync –avzhe ‘ssh –p 300’ /datafile [email protected]:/home/susan
# here, this example will let us use rsync over ssh with modified port.
rsync -azvh – -progress –include ‘A*’ –exclude ‘*’ [email protected]:/home/susan /datafile
# this will let us copy all files starting with “A” & will exclude all other files.
rsync -av --progress Music user@remote:
# Don't just sit there wondering about the status of your data transfer, use --progress
rsync -av . "$OLDPWD"/
# Copy the new/changed files in the current directory to the directory you were previously in.
# Backup with versioning
& 'C:\cwRsync_5.5.0_x86_Free\bin\rsync.exe' --force --ignore-errors --no-perms --chmod=ugo=rwX --checksum --delete --backup --backup-dir="_EVAC/$(Get-Date -Format "yyyy-MM-dd-HH-mm-ss")" --whole-file -a -v "//MyServer/MyFolder" "/cygdrive/c/Backup"
# Rsync using SSH and outputing results to a text file --delete will delete copies on remote to match local if deleted on local --stats will output the results -z zip -a archive -A preserve ACL -x don't cross filesystem boundaries -h human readable -e specify the remote shell to use
rsync --delete --stats -zaAxh -e ssh /local_directory/ username@IP_of_remote:/Remote_Directory/ > /Text_file_Directory/backuplog.txt
# rsync should continue even if connection lost - Manage partial uploads using append option.
rsync --archive --recursive --compress --partial --progress --append [email protected]:/backup/somefile.txt.bz2 /home/ubuntu/
# rsync using pem file - Especially useful while syncing to Amazon EC2 instance. avz stands for archive verbose compress
rsync -e 'ssh -i /root/my.pem' -avz /mysql/db/data_summary.* ec2-1-2-4-9.compute-1.amazonaws.com:/mysql/test/
#==============================##==============================#
# CMD RSYNC #
#==============================##==============================#
Cheatsheets are an excellent complement to other information sources like Linux man-pages, Linux help, or How-To’s and tutorials, as they provide compact and easily accessible information. While man-pages and detailed tutorials often contain comprehensive explanations and extensive guides, cheatsheets summarize the most important options forthe command rsync in a clear format. This allows users to quickly access the needed information for rsync without having to sift through lengthy texts. Especially in stressful situations or for recurring tasks, cheatsheets for rsync are a valuable resource to work efficiently and purposefully.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
█║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗██████╗
████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
╚██╔═██╔╝██║ ██║██║ ██║ ╚███╔╝ █████╗ ██║ ██║
████████╗██║ ██║██║ ██║ ██╔██╗ ██╔══╝ ██║ ██║
╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═════╝
█║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.