You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/backup/rsync_ssh.md
+18-18
Original file line number
Diff line number
Diff line change
@@ -12,20 +12,20 @@ tags:
12
12
This is everything you will need to understand and follow along with this guide:
13
13
14
14
- A computer running Rocky Linux
15
-
- To be comfortable with modifying configuration files from the command-line
15
+
- To be comfortable with modifying configuration files from the commandline
16
16
- Knowledge of how to use a command line editor (using _vi_ here, but you can use your favorite editor)
17
17
- You will need root access or `sudo` privileges
18
18
- Public and Private SSH key pairs
19
-
- Able to create a bash script with `vi` or your favorite editor, and test it.
19
+
- Able to create a bash script with `vi` or your favorite editor and test it.
20
20
- Able to use `crontab` to automate the running of the script
21
21
22
22
## Introduction
23
23
24
-
Using `rsync` over SSH is not as powerful as [lsyncd](../backup/mirroring_lsyncd.md) (which allows you to watch a directory or file for changes and keep it synchronized in realtime), nor as flexible as [rsnapshot](../backup/rsnapshot_backup.md) (which offers the ability to backup multiple targets from a single computer). However, it provides the ability to keep two computers up to date on a schedule that you define.
24
+
Using `rsync` over SSH is not as powerful as [lsyncd](../backup/mirroring_lsyncd.md) (which allows you to watch a directory or file for changes and keep it synchronized in real-time), nor as flexible as [rsnapshot](../backup/rsnapshot_backup.md) (which offers the ability to backup multiple targets from a single computer). However, it allows you to keep two computers up to date on a schedule you define.
25
25
26
26
If you need to keep a set of directories on the target computer up to date, and you do not care about real-time synchronization as a feature, then `rsync` over SSH is probably the best solution.
27
27
28
-
For this procedure, you will be doing things as the root user. Either login as root or use the `sudo -s` command to switch to the root user in your terminal.
28
+
For this procedure, you will be working as the root user. Either log in as root or use the `sudo -s` command to switch to the root user in your terminal.
29
29
30
30
### Installing `rsync`
31
31
@@ -35,15 +35,15 @@ Although `rsync` is probably already installed. To ensure that `rsync` is up to
35
35
dnf install rsync
36
36
```
37
37
38
-
If the package is not installed, `dnf` will ask you to confirm the installation, if it is already installed, `dnf` will look for an update and prompt to install it.
38
+
If the package is not installed, `dnf` will ask you to confirm the installation. If it is already installed, `dnf` will look for an update and prompt you to install it.
39
39
40
40
### Preparing the environment
41
41
42
42
This example will use `rsync` on the target computer to pull from the source instead of pushing from the source to the target. You need to set up an [SSH key pair](../security/ssh_public_private_keys.md) for this. After creating the SSH key pair, verify passwordless access from the target computer to the source computer.
43
43
44
44
### `rsync` parameters and setting up a script
45
45
46
-
Before script set up continues, you need to decide what parameters you want to use with `rsync`. Many possibilities exist. Review the [manual for rsync](https://linux.die.net/man/1/rsync) for a complete list. The most common way to use `rsync` is to use the `-a` option, because `-a`, or "archive", combines several common options into one. What does `-a` include?
46
+
Before the script setup continues, you must decide what parameters to use with `rsync`. Many possibilities exist. Review the [manual for rsync](https://linux.die.net/man/1/rsync) for a complete list. The most common way to use `rsync` is to use the `-a` option, because `-a`, or "archive", combines several common options. What does `-a` include?
47
47
48
48
-`-r`, recurse the directories
49
49
-`-l`, maintains symbolic links as symbolic links
@@ -58,7 +58,7 @@ The only other options that you need to specify in this example are:
58
58
-`-e`, specify the remote shell to use
59
59
-`--delete`, which says if the target directory has a file in it that does not exist on the source, get rid of it
60
60
61
-
Next, set up a script on the target computer by creating a file for it (again, use your favorite editor if you are not familiar with `vi`). To create the file, just use this command:
61
+
Next, set up a script on the target computer by creating a file for it (again, use your favorite editor if you are unfamiliar with `vi`). To create the file, use this command:
Replace "source.domain.com" with your own domain name, host name, or IP address.
74
+
Replace "source.domain.com" with your domain name, hostname, or IP address.
75
75
76
76
Make it executable:
77
77
@@ -93,15 +93,15 @@ Run the script:
93
93
/usr/local/sbin/rsync_dirs
94
94
```
95
95
96
-
If all is well, you will get a completely synchronized copy of your home directory on the target computer. Ensure this is the case.
96
+
If all is well, you will get a synchronized copy of your home directory on the target computer. Ensure this is the case.
97
97
98
98
Assuming all of that worked, create a new file on the source computer in your home directory:
99
99
100
100
```bash
101
101
touch /home/your_user/testfile.txt
102
102
```
103
103
104
-
Run the script again:
104
+
Rerun the script:
105
105
106
106
```bash
107
107
/usr/local/sbin/rsync_dirs
@@ -113,7 +113,7 @@ Verify that the target computer receives the new file. If so, the next step is t
113
113
rm -f /home/your_user/testfile.txt
114
114
```
115
115
116
-
Run the script again:
116
+
Rerun the script:
117
117
118
118
```bash
119
119
/usr/local/sbin/rsync_dirs
@@ -133,13 +133,13 @@ Run the script a final time:
133
133
/usr/local/sbin/rsync_dirs
134
134
```
135
135
136
-
The file you created on the target should no-longer exist, because it does not exist on the source.
136
+
The file you created on the target should nolonger exist because it does not exist on the source.
137
137
138
-
Assuming all of this worked as expected, change the script to synchronize all the directories that you want.
138
+
Assuming all of this worked as expected, change the script to synchronize all the directories you want.
139
139
140
140
## Automating everything
141
141
142
-
You probably do not want to manually run this script every time you want to synchronize. Use a `crontab` to do this automatically on a schedule. To run this script at 11 PM every night:
142
+
You may not want to run this script every time you want to synchronize manually. Use a `crontab` to do this automatically on a schedule. To run this script at 11 PM every night:
143
143
144
144
```bash
145
145
crontab -e
@@ -175,15 +175,15 @@ This will pull up and look similar to this:
175
175
176
176
!!! info
177
177
178
-
The example `crontab` shows an empty, but commented, file. The commenting does not show up on every computer instance and may be an empty file. On an active computer, you may see other entries.
178
+
The example `crontab` shows an empty but commented file. The commenting does not appear on every computer instance and may be an empty file. On an active computer, you may see other entries.
179
179
180
-
The `crontab` is on a 24-hour clock. You will need your entry at the bottom of this file is:
180
+
The `crontab` is on a 24-hour clock. You will need your entry at the bottom of this file:
181
181
182
182
```crontab
183
183
00 23 * * * /usr/local/sbin/rsync_dirs
184
184
```
185
185
186
-
What this says is to run this command at 00 minute, 23 h, every day, every month, and every day of the week. Save your `crontab` entry with:
186
+
What this says is to run this command at 00 minutes, 23 h, every day, every month, and every day of the week. Save your `crontab` entry with:
187
187
188
188
++shift+colon+"w"+"q"+exclam++
189
189
@@ -198,4 +198,4 @@ What this says is to run this command at 00 minute, 23 h, every day, every month
198
198
199
199
## Conclusions
200
200
201
-
Although `rsync` is not as flexible or powerful as other tools, it provides file synchronization, which is always useful.
201
+
Although `rsync` is not as flexible or robust as other tools, it provides file synchronization, which is always helpful.
0 commit comments