Skip to content

Commit

Permalink
#1867 fix markdown violation in backup (#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
nishaaaaaant authored Mar 29, 2024
1 parent 4002613 commit e2a33fe
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 62 deletions.
51 changes: 26 additions & 25 deletions docs/guides/backup/mirroring_lsyncd.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ tags:

This is everything you'll need to understand and follow along with this guide:

* A computer running Rocky Linux
* A comfort level with modifying configuration files from the command-line
* Knowledge of how to use a command line editor (we use vi here, but you could use your favorite editor)
* You will need root access, and ideally be signed in as the root user in your terminal
* Public and Private SSH key pairs
* The EPEL repositories from Fedora
* You will need to be familiar with *inotify*, an event monitor interface
* Optional: familiarity with *tail*
- A computer running Rocky Linux
- A comfort level with modifying configuration files from the command-line
- Knowledge of how to use a command line editor (we use vi here, but you could use your favorite editor)
- You will need root access, and ideally be signed in as the root user in your terminal
- Public and Private SSH key pairs
- The EPEL repositories from Fedora
- You will need to be familiar with *inotify*, an event monitor interface
- Optional: familiarity with *tail*

## Introduction

Expand Down Expand Up @@ -105,7 +105,7 @@ Now change directories again so that you are in the build directory:

Now run these commands:

```
```bash
cmake ..
make
make install
Expand All @@ -127,7 +127,7 @@ This file can be created anywhere, even in the root directory of your server. Wh

The contents of this file should be:

```
```bash
[Unit]
Description=Live Syncing (Mirror) Daemon
After=network.target
Expand All @@ -143,6 +143,7 @@ PIDFile=/run/lsyncd.pid
[Install]
WantedBy=multi-user.target
```

Now let's install the file you just made to the correct location:

`install -Dm0644 /root/lsyncd.service /usr/lib/systemd/system/lsyncd.service`
Expand All @@ -159,7 +160,7 @@ Whichever method you choose for installing `lsyncd`, you will need a configurati

Here's an example of a simplistic configuration file that synchronizes */home* to another computer. Our target computer is going to be a local IP address: *192.168.1.40*

```
```bash
settings {
logfile = "/var/log/lsyncd.log",
statusFile = "/var/log/lsyncd-status.log",
Expand All @@ -186,28 +187,28 @@ sync {

Breaking down this file a bit:

* The "logfile" and "statusFile" will be automatically created when the service starts.
* The "statusInterval" is the number of seconds to wait before writing to the statusFile.
* "maxProcesses" is the number of processes `lsyncd` is allowed to spawn. Honestly, unless you are running this on a super busy computer, 1 process is enough.
* In the sync section "default.rsyncssh" says to use rsync over SSH
* The "source=" is the directory path we are syncing from.
* The "host=" is our target computer that we are syncing to.
* The "excludeFrom=" tells `lsyncd` where the exclusions file is. It must exist, but can be empty.
* The "targetdir=" is the target directory we are sending files to. In most cases this will be equal to the source, but not always.
* Then we have the "rsync =" section, and these are the options that we are running rsync with.
* Finally we have the "ssh =" section, and this specifies the SSH port that is listening on the target computer.
- The `logfile` and `statusFile` will be automatically created when the service starts.
- The `statusInterval` is the number of seconds to wait before writing to the statusFile.
- `maxProcesses` is the number of processes `lsyncd` is allowed to spawn. Honestly, unless you are running this on a super busy computer, 1 process is enough.
- In the sync section `default.rsyncssh` says to use rsync over SSH
- The `source=` is the directory path we are syncing from.
- The `host=` is our target computer that we are syncing to.
- The `excludeFrom=` tells `lsyncd` where the exclusions file is. It must exist, but can be empty.
- The `targetdir=` is the target directory we are sending files to. In most cases this will be equal to the source, but not always.
- Then we have the `rsync =` section, and these are the options that we are running rsync with.
- Finally we have the `ssh =` section, and this specifies the SSH port that is listening on the target computer.

If you are adding more than one directory to sync, then you need to repeat the entire "sync" section including all the opening and closing brackets for each directory.

## The lsyncd.exclude File

As noted earlier, the "excludeFrom" file must exist, so let's create that now:
As noted earlier, the `excludeFrom` file must exist, so let's create that now:

`touch /etc/lsyncd.exclude`

If you were syncing the /etc folder on our computer, there would be many files and directories that you should exclude. Each excluded file or directory is listed in the file, one per line, like this:
If you were syncing the `/etc` folder on our computer, there would be many files and directories that you should exclude. Each excluded file or directory is listed in the file, one per line, like this:

```
```bash
/etc/hostname
/etc/hosts
/etc/networks
Expand Down Expand Up @@ -248,7 +249,7 @@ Anytime you are synchronizing a set of files or directories to another computer,

For newbies, *fstab* is the file that is used to configure storage drives on any Linux computer. The disks and labels are almost certainly different. The next time the target computer was rebooted it would likely fail to boot entirely.

# Conclusions And References
## Conclusions And References

`lsyncd` is a powerful tool for directory synchronization between computers. As you've seen, it is not hard to install, and it is not complex to maintain going forward. You can not ask for more than that.

Expand Down
34 changes: 17 additions & 17 deletions docs/guides/backup/rsnapshot_backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ tags:

## Prerequisites

* Know how to install additional repositories and snapshots from the command-line
* Know about mounting filesystems external to your machine (external drive, remote filesystem, and so on.)
* Know how to use an editor (using `vi` here, but you can use your favorite editor)
* Know a little BASH scripting
* Know how to change the crontab for the root user
* Knowledge of SSH public and private keys (only if you plan to run remote backups from another server)
- Know how to install additional repositories and snapshots from the command-line
- Know about mounting filesystems external to your machine (external drive, remote filesystem, and so on.)
- Know how to use an editor (using `vi` here, but you can use your favorite editor)
- Know a little BASH scripting
- Know how to change the crontab for the root user
- Knowledge of SSH public and private keys (only if you plan to run remote backups from another server)

## Introduction

Expand Down Expand Up @@ -224,7 +224,7 @@ Earlier versions of _rsnapshot_ had `hourly, daily, monthly, yearly` but are now

In this example, you are not going to be running any other increments other than a nightly backup. Just add a remark to alpha and gamma. When completed, your configuration file will be:

```
```text
#retain alpha 6
retain beta 7
#retain gamma 4
Expand Down Expand Up @@ -265,7 +265,7 @@ Again, to do this you do not necessarily have to specify the configuration in th

Which will return something similar to this, showing you what will happen when the backup is actually run:

```
```bash
echo 1441 > /var/run/rsnapshot.pid
mkdir -m 0755 -p /mnt/backup/storage/beta.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
Expand Down Expand Up @@ -305,7 +305,7 @@ If you have not run this before, choose vim.basic as your editor or your own edi

You are going to set your backup to automatically run at 11 PM, so you will add this to the crontab:

```
```bash
## Running the backup at 11 PM
00 23 * * * /usr/bin/rsnapshot -c /etc/rsnapshot.conf beta`
```
Expand All @@ -318,13 +318,13 @@ If running these backups over the Internet, you need to ensure that each locatio

## Assumptions

Running _rsnapshot_ from a machine remotely, on-premise. Running this exact configuration is possible remotely off-premise also.
Running _rsnapshot_ from a machine remotely, on-premise. Running this exact configuration is possible remotely off-premise also.

In this case, you will want to install _rsnapshot_ on the machine that is doing all of the backups. Other assumptions are:

* That the servers you will be backing up to, have a firewall rule that allows the remote machine to SSH into it
* That each server that you will be backing up has a recent version of `rsync` installed. For Rocky Linux servers, run `dnf install rsync` to update your system's version of `rsync`.
* That you have connected to the machine as the root user, or that you have run `sudo -s` to switch to the root user
- That the servers you will be backing up to, have a firewall rule that allows the remote machine to SSH into it
- That each server that you will be backing up has a recent version of `rsync` installed. For Rocky Linux servers, run `dnf install rsync` to update your system's version of `rsync`.
- That you have connected to the machine as the root user, or that you have run `sudo -s` to switch to the root user
## SSH public or private keys
Expand Down Expand Up @@ -364,7 +364,7 @@ Next, you want to change rsnapshot_web.conf so that it includes the directories

Here is an example of the web.ourdomain.com configuration:

```
```bash
### BACKUP POINTS / SCRIPTS ###
backup [email protected]:/etc/ web.ourourdomain.com/
backup [email protected]:/var/www/ web.ourourdomain.com/
Expand Down Expand Up @@ -393,7 +393,7 @@ Automating backups for the multiple machine or server version is slightly differ

With the content:

```
```bash
#!/bin/bash/
# script to run rsnapshot backups in succession
/usr/bin/rsnapshot -c /etc/rsnapshot_web.conf beta
Expand All @@ -411,7 +411,7 @@ Create the crontab for root to run the backup script:

Add this line:

```
```bash
## Running the backup at 11 PM
00 23 * * * /usr/local/sbin/backup_all
```
Expand All @@ -422,7 +422,7 @@ To ensure that everything is backing up according to plan, you might want to sen

## Restoring a backup

Restoring a few files or an entire backup involves copying the files you want from the directory with the date that you want to restore from back to your machine.
Restoring a few files or an entire backup involves copying the files you want from the directory with the date that you want to restore from back to your machine.

## Conclusions and other resources

Expand Down
41 changes: 21 additions & 20 deletions docs/guides/backup/rsync_ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ tags:

This is everything you will need to understand and follow along with this guide:

* A machine running Rocky Linux
* To be comfortable with modifying configuration files from the command-line
* Knowledge of how to use a command line editor (using _vi_ here, but you can use your favorite editor)
* You will need root access, and ideally be signed in as the root user in your terminal
* Public and Private SSH key pairs
* Able to create a bash script with `vi` or your favorite editor, and test it.
* Able to use _crontab_ to automate the running of the script
- A machine running Rocky Linux
- To be comfortable with modifying configuration files from the command-line
- Knowledge of how to use a command line editor (using _vi_ here, but you can use your favorite editor)
- You will need root access, and ideally be signed in as the root user in your terminal
- Public and Private SSH key pairs
- Able to create a bash script with `vi` or your favorite editor, and test it.
- Able to use _crontab_ to automate the running of the script

## Introduction

Expand All @@ -45,18 +45,18 @@ This particular example will use `rsync` on the target machine to pull from the

Before we get terribly carried away with setting up a script, we first need to decide what parameters we want to use with `rsync`. There are many possibilities, so take a look at the [manual for rsync](https://linux.die.net/man/1/rsync). The most common way to use `rsync` is to use the `-a` option, because `-a`, or archive, combines a number of options into one and these are very common options. What does -a include?

* -r, recurses the directories
* -l, maintains symbolic links as symbolic links
* -p, preserves permissions
* -t, preserves modification times
* -g, preserves group
* -o, preserves owner
* -D, preserves device files
- `-r`, recurses the directories
- `-l`, maintains symbolic links as symbolic links
- `-p`, preserves permissions
- `-t`, preserves modification times
- `-g`, preserves group
- `-o`, preserves owner
- `-D`, preserves device files

The only other options that we need to specify in this example are:

* -e, specify the remote shell to use
* --delete, which says if the target directory has a file in it that doesn't exist on the source, get rid of it
- `-e`, specify the remote shell to use
- `--delete`, which says if the target directory has a file in it that doesn't exist on the source, get rid of it

Next, we need to set up a script 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:

Expand All @@ -70,7 +70,7 @@ And then make it executable:

Now, scripting makes it super simple and safe so that you can test it fearlessly. Please note that the URL used below is "source.domain.com". Replace it with the domain or IP address of your own source computer, both will work. Also remember that in this example, the script is created on the "target" computer, because the file is pulled from the source computer:

```
```bash
#!/bin/bash
/usr/bin/rsync -ae ssh --delete [email protected]:/home/your_user /home
```
Expand Down Expand Up @@ -148,25 +148,26 @@ This will pull up the cron, which may look something like this:
#
# m h dom mon dow command
```

The cron is set up on a 24-hour clock, so what we will need for our entry at the bottom of this file is:

`00 23 * * * /usr/local/sbin/rsync_dirs`

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 cron entry with:

`Shift : wq!`
++shift+colon+"w"+"q"+exclam++

... or with the commands that your favorite editor uses for saving a file.

## Optional Flags
```

```bash
-n : Dry-Run to see what files wouold be transferred
-v : list out all the files which are being transferred
-vvv : to provide debug info while transferring files
-z : to enable compression during the transfer
```

## Conclusions
Although `rsync` is not as flexible or powerful as other tools, it provides simple file synchronization, which is always useful.

0 comments on commit e2a33fe

Please sign in to comment.