User Tools

(aka 'the best point military institute')

Site Tools

tools:rsync

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:rsync [2025/10/12 06:23] – [Incremental Backups] Humphrey Boa-Garttools:rsync [2025/10/12 07:40] (current) – [rsync] Humphrey Boa-Gart
Line 1: Line 1:
 ====== rsync ====== ====== rsync ======
  
-{{wst>expand}}+**rsync** //(or **remote sync**)// is a [[tools:bash|command line]] utility for transferring and synchronizing files between any given //"source"// and //"destination"// pair. It is extremely popular for use in backup utilities, at it can synchronize backups between not only local filesystems, but also over the internet via [[tools:ssh|SSH]].
  
 +While you can technically use the ''cp -R'' command to make quick and dirty backups, ''rsync'' offers far more flexibility for many common real-world scenarios.
 +
 +If you are already familiar with using [[tools:wget|Wget]] to make mirrors of entire websites, then use of ''rsync'' should come to you pretty naturally - it just operates over local filesystems & SSH instead of HTTP/HTTPS/FTP.
  
 ===== Useful Commands ===== ===== Useful Commands =====
Line 34: Line 37:
   $ rsync -avz -e ssh user@remote:/source/directory/ /destination/directory/   $ rsync -avz -e ssh user@remote:/source/directory/ /destination/directory/
  
-In the case of both of these commands, //"local shell"// just means whatever terminal you are running ''rsync'' from. If you are running this from a remote machine, that machine is the "local shell" in this equation, and whatever machine it is SSH'ing into is the "remote shell." Make sense? Good, because there's a few more things you have to grasp with this commandor you're going to make an absolute mess of your files.+In the case of both of these commands, //"local shell"// just means whatever terminal you are running ''rsync'' from. And no, you cannot use ''rsync'' between a remote source and remote destination at the same time: 
 + 
 +  $ rsync -avz -e ssh user@remote1:/source/directory/ user@remote2:/destination/directory/ 
 +  The source and destination cannot both be remote. 
 + 
 +So if you want to sync between two remote machines, you will have to first SSH into one of them and run ''rsync'' from there "locally" with the other machine as the remote. 
  
 ==== Incremental Backups ==== ==== Incremental Backups ====
Line 47: Line 56:
  
 If you are looking for an even more failsafe way to ensure the quality of backups, use the ''-c'' flag to have ''rsync'' compare checksums of every conflicting file transfer instead of modification times. This method is a lot slower, but far more accurate when left on autopilot. If you are looking for an even more failsafe way to ensure the quality of backups, use the ''-c'' flag to have ''rsync'' compare checksums of every conflicting file transfer instead of modification times. This method is a lot slower, but far more accurate when left on autopilot.
 +
 +==== Interrupted Backups ====
 +
 +When ''rsync'' has one of its backup runs interrupted, it just stops. Any files that were finished, you get to keep. Whatever file it was on last, is lost. Just run ''rsync'' again in incremental mode //(see above)// and it will start over on whatever file it was processing when it was interrupted.
 +
 +However, if you're dealing with very large files, you do not want to have to start over. Use the ''-P'' flag if you want to keep partially-downloaded files, so you can resume transfers mid-file instead of between files.
  
  
Line 58: Line 73:
  
   $ rsync -av --exclude-from 'exclusions.txt' /path/to/source/dir/ /path/to/destination/dir/   $ rsync -av --exclude-from 'exclusions.txt' /path/to/source/dir/ /path/to/destination/dir/
 +
 +You can even exclude things like specific filetypes:
 +
 +  $ rsync -av --exclude='*.ext' /path/to/source/dir/ /path/to/destination/dir/
  
  
Line 67: Line 86:
   * Use ''--progress'' to see real-time transfer status.   * Use ''--progress'' to see real-time transfer status.
   * Use ''--log-file=transfer.log'' to generate a log file of the transfer.   * Use ''--log-file=transfer.log'' to generate a log file of the transfer.
 +  * Use ''--remove-source-files'' to delete the source directory once the transfer is complete.
  
  
tools/rsync.1760250221.txt.gz · Last modified: by Humphrey Boa-Gart

Find this page online at: https://bestpoint.institute/tools/rsync