{
 "id": 36964,
 "slug": "2020-10-30_how-to-use-rsync-to-make-backups",
 "url": "https://agents.willem.com/en/posts/2020-10-30_how-to-use-rsync-to-make-backups/",
 "source_url": "https://willem.com/en/2020-10-30_how-to-use-rsync-to-make-backups/",
 "language": "en",
 "date": "2020-10-30",
 "published": "2020-10-30T00:00:00+01:00",
 "created": "2025-06-26T22:09:47.393000+02:00",
 "updated": "2025-07-22T16:42:43.704000+02:00",
 "title": "How to use rsync to make backups",
 "subtitle": "Explaining a powerful file transfer tool",
 "summary": "It is very important to make backups of your data, as you never know when disaster strikes! One powerful, cross platform, tool to help you achieve this is 'rsync'.  In this post I'll explain why rsync is useful and how you can use it to set up your own backups.",
 "topics": [
  "Freedom",
  "SSH",
  "Windows",
  "data",
  "howto",
  "linux",
  "networking",
  "server"
 ],
 "author": {
  "name": "Willem L. Middelkoop",
  "url": "https://willem.com"
 },
 "translation": {
  "language": "nl",
  "url": "https://agents.willem.com/nl/posts/2020-10-30_hoe-rsync-te-gebruiken-voor-backups/",
  "source_url": "https://willem.com/nl/2020-10-30_hoe-rsync-te-gebruiken-voor-backups/"
 },
 "image": "https://willem.com/global/images/56f73e945374.webp",
 "image_width": 2560,
 "images": [
  {
   "url": "https://willem.com/global/images/7a7bafa71781.webp",
   "description": "Typical rsync command, showing the -arvz flags, a My-Source-Directory and My-Remote-Directory on a server",
   "manager_file": "148-bf2d6faf6057f115dc72e82d984e71359f16b48d8c42b4b41c2ee918cf46b556_ContentAsPost_36964_images-1.png"
  },
  {
   "url": "https://willem.com/global/images/0c7ba3c82117.webp",
   "description": "Using rsync on Windows 10 using WSL",
   "manager_file": "148-bf2d6faf6057f115dc72e82d984e71359f16b48d8c42b4b41c2ee918cf46b556_ContentAsPost_36964_images-2.png"
  },
  {
   "url": "https://willem.com/global/images/c497fa4abfcc.webp",
   "description": "Using rsync to copy files from my Windows 10 desktop to a Debian GNU/Linux server over SSH (using WSL)",
   "manager_file": "148-bf2d6faf6057f115dc72e82d984e71359f16b48d8c42b4b41c2ee918cf46b556_ContentAsPost_36964_images-3.png"
  },
  {
   "url": "https://willem.com/global/images/d76217c9a685.webp",
   "description": "After adding the Milky Way photo to my sample files I run rsync again to use have it transfer my files incrementally, only copying the new file",
   "manager_file": "148-bf2d6faf6057f115dc72e82d984e71359f16b48d8c42b4b41c2ee918cf46b556_ContentAsPost_36964_images-4.png"
  }
 ],
 "text": "Rsync\nEver since it was originally created in 1996 (by Andrew Tridgell and Paul Mackerras), rsync has grown to become a standard utility that is available on popular GNU/Linux distributions, Apple macOS, FreeBSD, NetBSD, OpenBSD and (through Cygwyn or WSL) on Windows.\nKey features\nRsync is typically used for synchronising files and directories between two different computers. It can use SSH to connect to another computer and to transfer files. In addition to remote computers, you can use rsync to synchronise to external hard drives and network attached storage (NAS) drives. Rsync is popular because:\n- It is licensed under the GNU_General_Public_License (https://en.wikipedia.org/wiki/GNU_General_Public_License), making it free software; both free as in \"free speech\" and \"free beer\"\n- Rsync's algorithm is a type of delta_encoding (https://en.wikipedia.org/wiki/Delta_encoding) meaning that it minimises data / network traffic as it only copies the parts of the files that have changed. In addition, data can be compressed to even further optimise the file transfer traffic.\n- It can resume interrupted transfers by using checksum verification. This allows rsync to detect errors when copying a file from one place to another. If two files differ by just one bit, their checksums would become different. Checksum verification is an efficient way to check that every byte was properly transferred to its destination.\nInstalling rsync\nIf you're on GNU/Linux, *BSD or Apple macOS you probably already have rsync installed. If you're on Windows you can look_at_the_Windows_Subsystem_for_Linux_or_WSL (https://docs.microsoft.com/en-us/windows/wsl/install-win10) to get access to all the standard GNU/Linux tools. Alternatively to WSL, you can use Cygwin (https://www.cygwin.com/) to install the large collection of GNU and Open Source tools on Windows.\nTypical usage of rsync\nUsing rsync is done from the command line, or terminal. You run the 'rsync' command followed by (optional) flags, a source path and a destination path.\nUsing the -arvz flags you configure rsync to:\n- a: \"archive\" mode which preserves permissions, created and last updated times\n- r: \"recursive\" mode enables rsync to recursively synchronise subfolders inside the source/target directories\n- v: \"verbose\" will enable more verbose output on the console, allowing you to track its progress, line by line\n- z: \"compress\" will enable the compression of data as it is sent to the destination machine, which reduces the amount of data being transmitted, useful over slow or metered connections\n- --delete: will enable files to be removed on the remote side if they are removed from the source directory. You should be careful with this option!\nThere are many other flags and options which allow you to customise the behaviour of rsync to your needs. You should check out the man_page_for_rsync (https://www.man7.org/linux/man-pages/man1/rsync.1.html) for a full list of all options.\nHow to use rsync to backup files\nIn the following example I'll use rsync to copy a directory (\"Sample-Files\") on my Windows 10 desktop to a remote server. I use WSL_on_Windows (https://docs.microsoft.com/en-us/windows/wsl/install-win10) to have a working Debian_GNU/Linux environment in my Windows Terminal.\nLet me explain the command that I use:\n- rsync is the name of the program that I use\n- -arvz are the flags that configure rsync to make an archived backup, including subdirectories and transfer data using compression\n- /mnt/c/Users/mail/Desktop/Sample-files/ is the path to the source directory as seen through the WSL directory structure. It points to my Windows desktop (which is on the C: drive)\n- willem @ store.willem.com:./Backup is the destination, which you should read as \"user willem at the server 'store.willem.com'\", and \"on that server\" use the \"Backup\" folder inside the \"./\" home directory of the \"willem user\".\nIf you execute this command for the first time, the remote server's cryptographic fingerprint is shown. This is used to ensure that you're talking to your server. This prevents hackers to impersonate your server without you noticing (as the fingerprint is unique to your server. If rsync detects a change in this fingerprint, it will refuse to transfer files. This is critical as copying your backups to a random remote destination would be a potential risk for data leaks!\nYou're asked for your password if you're connecting over SSH without key-based authentication. This is fine if you intend to run your file transfer manually, but if you intend to automate transfers you might want to setup_key-based_authentication (https://www.redhat.com/sysadmin/configure-ssh-keygen) (using the handy command \"ssh-copy-id\"). You're computer will then be able to securely login to the remote machine without the need to enter a password manually.\nIf rsync can connect successfully it will then continue to determine which files need to be transferred. If you have set the \"-v\" flag, you'll see the progress line by line. After the transfer is complete rsync will exit with a summary.\nIncremental transfers\nRsync's party trick is that it fully supports incremental data transfers out of the box. If you have some new files and then run the same rsync command again, it will only transfer those files that are in need of transfer.\nYou can see in the screenshot that rsync automatically detected the new file. It only transferred that file to the remote server. Saving bandwidth, time and processing power. It works with new files and files that have been updated.\nOptionally you can use the \"--delete\" flag to propagate local deletes to the target directory, creating a perfect mirror image of the local file structure. For backup purposes you might consider skipping this (as you might remove files unintentionally).\nAutomating transfers and backups\nBecause rsync is \"just a terminal command\" you can easily use it inside your own scripts. Think of a script as a collection of rsync commands that comprise a set of \"source\" and \"destination\" links between your files and their respective backup locations.\nYou can schedule your script to be executed automatically at a given day of the week and time of the day. On GNU/Linux, *BSD and macOS you can use cron to do this. On Windows you can use the \"Task Scheduler\" app.\nConclusion\nWith rsync you can transfer files from your computer to another system efficiently, securely and incrementally. It can be a crucial tool in your backup schedule.\nIt is free and widely available. Its performance and reliability are widely established. There really is no excuse for why you shouldn't setup your backups properly!",
 "word_count": 1035,
 "markdown_url": "https://agents.willem.com/en/posts/2020-10-30_how-to-use-rsync-to-make-backups/post.md"
}