![]() |
VOOZH | about |
Rsync, which stands for remote sync, is a command-line tool for synchronizing files and directories locally and remotely. It uses a delta-transfer algorithm to minimize the amount of data copied by moving only the portions of files that have changed, making it highly efficient for tasks like backups and mirroring.
In this guide, you will learn how to use rsync for various file management tasks. We will cover its basic syntax, how to transfer files to and from a remote server, and how to use common options like --delete for mirroring and --dry-run for safe testing. You will also learn how to automate transfers with cron and troubleshoot frequent issues.
Deploy your frontend applications from GitHub using DigitalOcean App Platform. Let DigitalOcean focus on scaling your app.
Key Takeaways:
rsync is a file synchronization tool that efficiently copies local and remote directories by transferring only the changed portions of files./) on the source path is critical, as it dictates whether rsync copies the contents of the directory or the directory itself.rsync commands with the --dry-run or -n flag to preview the outcome without making any actual changes to the files.-a (archive) flag is recommended for most use cases because it syncs recursively while preserving permissions, ownership, and modification times.--delete option to remove files from the destination that are no longer present in the source directory.-z flag compresses file data to reduce network usage, and the -P flag shows progress while allowing interrupted transfers to be resumed.rsync uses SSH for secure remote operations, enabling you to βpushβ files to a remote system or βpullβ files from it.cron, which requires using absolute paths in your command and configuring passwordless SSH key authentication.Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Educator and writer committed to empowering our community by providing access to the knowledge and tools for making creative ideas into a reality
Former Senior Technical Writer at DigitalOcean, specializing in DevOps topics across multiple Linux distributions, including Ubuntu 18.04, 20.04, 22.04, as well as Debian 10 and 11.
With over 6 years of experience in tech publishing, Mani has edited and published more than 75 books covering a wide range of data science topics. Known for his strong attention to detail and technical knowledge, Mani specializes in creating clear, concise, and easy-to-understand content tailored for developers.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Is it possible to backup multiple folders are once over SSH? Locally, this command works fine:
rsync -av /{folder1, folder2} /backup
But when run over ssh, it fails. Any ideas? The paths are correct and work when run individually. I am on OS X if that matters.
@TheUnknown: βBut when run over sshβ - what command do you try to run exactly?
Oh. Glad it works now! :]
I am still not able to transfer multiple folders over SSH, I just made a typo in my example. Sorry if I was not clear.
Is this a permanent connection so if file 1 changes on server 1 then its sent to directory2 on server 2? Or is it temporary and must be done manually?
Is it similar to lncron? Is one better to have change automatically updated on remote host?
Thanks.
@phillip: rsync only runs when you run the command. It doesnβt automatically sync both servers, take a look at <a href=βhttps://code.google.com/p/lsyncd/β>lsyncd</a>.
Most useful post Kamal. Thanks a lot !!
My Apologies Justin. I meant you not Kamal. Thanks for this most informative post.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.