From 8d4177c694b51c72f76c7bf39bc52f2b7bbd8769 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Sat, 3 Jul 2021 08:59:22 -0400 Subject: rsync fixes --- rsync.html | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'rsync.html') diff --git a/rsync.html b/rsync.html index dc9defb..da4bd15 100644 --- a/rsync.html +++ b/rsync.html @@ -1,7 +1,7 @@ - Using rsync for your website or server + Rsync: Upload and Sync Files and Websites – LandChad.net @@ -10,26 +10,46 @@ -

Using rsync for website and servers

+

Rsync: Upload and Sync Files and Websites

-

So you have a website and you have ssh setup on your server. Rsync is a way of uploading and downloading files to and from your server. Here is how.

+

rsync is a simple way to copy files and folders between your local computer and server.

+

It not only makes file-transfer easy, but it allows you to build and maintain your website offline, then easily upload it to the proper directory on your server so you don't need to constantly be logged into your server to modify your site.

Installing rsync

-

Run the following on your server and on your local machine.

+

Run the following on your server and on your local machine.

apt install rsync

Uploading files with rsync

From your local machine you can upload files to your server like this:

-
rsync -avz /path/to/file landchad.net:/path/on/the/server
-

You will be prompted to enter a password. By default it will use the username that you are logged in with on you local machine. To use a different user, do this:

-
rsync -avz /path/to/file username@landchad.net:/path/on/the/server
-

Downloading file with rsync

-

Basically like downloading, you just swap the last two arguments, like this:

-
rsync -avz landchad.net:/path/to/file /path/to/file
-

Again, with a different username on you server:

-
rsync -avz username@landchad.net:/path/to/file /path/to/file
-

Contribution

-

el3ctr0lyte: github, XMR: 86DBJdiG83ZDea6kJgsbVN5tMae5ScfuhJ3PihEMTHatCrGEw2gctyUB92V2fz4R4YhwRaQeAGL5M4gPRXvVvtkULJi4ayk

+
rsync -ruvzP /path/to/file root@example.org/path/on/the/server
+

You will be prompted for the root password and then uploading will commence.

+

If you omit root@, rsync will not attempt to log in as root, but whatever your local username is.

+

Options to rsync

+

In this command, we give several options to rsync:

+ +

Avoid using the commonly used -a option when uploading. It changes can transfer your local machine's user and group permissions to your server, which might cause breakage.

+

Scriptability

+

It's a good idea to build your website offline, then make an rsync script or bash alias like the one above to upload the edited files when you have made updates.

+

Password-less authentication

+

To avoid having to manually input your password each upload, you can set up SSH keys to securely idenitify yourself and computer as a trusted.

+

Picky trailing slashes

+

rsync is very particular about trailing slashes. This is useful, but can be confusing to some new users. Suppose we run the following wanting to mirror our offline copy of our website in the directory we use on our server (/var/www/websitefiles/):

+
rsync -ruvzP ~/websitefiles/ root@example.org:/var/www/websitefiles/
+

This will not actually do quite what we want. It will take our local websitefiles directory and put it inside websitefiles on the remote machine, ending up with: /var/www/websitefiles/websitefiles.

+

Instead, remove the trailing slash from the remote server location:

+
rsync -ruvzP ~/websitefiles/ root@example.org:/var/www/websitefiles
+

websitefiles/ has been replaced with websitefiles, and this will do what we want.

+

Downloading files with rsync

+

You may just as easily download files and directories from your server with rsync:

+
rsync -urvzP root@example.org:/path/to/file /path/to/file
+

Contribution

+
- + -- cgit v1.2.3