blog-image

May 01, 2019

11 min read

Back Up Your Files With rsync And A VPS

Written by

Vippy The VPS

rsync is an open source tool for copying and synchronizing files both locally and remotely across Unix-based systems. It's not only fast, but also smart—the tool utilizes a famous algorithm to detect the "delta" between two files or folders. This reduces the amount of data sent over the network by only transferring the pieces of files that changed.

Let's say you have a folder a that contains files b.txt, c.txt, and d.txt. When you first use rsync to copy that directory to another location, every file is transferred along with its contents. But let's say you add a few sentences to c.txt, and then run rsync again. This time, it will only copy those sentences you made to c.txt. Because b.txt and d.txt were unchanged, there's no reason to copy them again.

That means that rsync is great for backups, because it can dramatically reduce the amount of network transfer. Many people either set up a VPS that they dedicate toward backing up important personal documents, or utilize the leftover disk space on an existing VPS.

[cta_inline]

So, let's walk through one option for an automated backup system. This isn't meant to be a definitive guide to using rsync as a backuptool, and will only cover using your VPS as a remote backup for files you keep on your local machine.

But, once you have some of these fundamentals figured out, you'll be able to use them toward a variety of use cases, such as setting up automated backups between two VPSes and more.

May 1: Updated with an improved version of the rsync + Bash script that actually works! Thanks to John for helping track this one down.

Prerequisites

  • A local machine running Linux or OS X
  • A virtual private server running Ubuntu 12.04/14.04/16.04, Fedora 22, Debian 7/8, CentOS 6/7
  • SSH access to your VPS

Rsync basics

If rsync isn't installed on your system yet, you can get it with your package manager.

$ sudo apt-get install rsync   # for Debian/Ubuntu
$ sudo yum install rsync       # for Fedora/CentOS

The most basic rsync operation is between two local folders. the -a option enables "archive" mode, which is equal to -rlptgoD—check the man page for more information. The -v option enables "verbose" mode, which makes troubleshooting easier.

$ rsync -av source/ destination/

Or, when copying between a local machine and a remote one, such as a VPS, over the SSH protocol:

$ rsync -av -e ssh 
Continue reading this article
by subscribing to our newsletter.
Subscribe now

A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.

If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.

Leave a Reply