# Backup, Recovery and Replication

## Recovery

This section provides a comprehensive guide for setting up recovery between two ZS3Servers.&#x20;

This setup uses the Blimp UI for deployment, Visual Studio Code for configuration, and MinIO Client (mc) for management.&#x20;

Whether you're new to ZS3Server or an experienced user, this guide offers detailed instructions for every stage of the process.

### Step 1: Deploy ZS3Server1

1. Go to "Manage Allocations" and select "S3 Setup." and click on create new allocation

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FGNtuQ0sx39Tirl3hgGjv%2Fimage.png?alt=media&#x26;token=61599296-8f77-43da-8ba1-81aabc0fc8f2" alt=""><figcaption><p>Fig1: Manage Allocations</p></figcaption></figure>

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FfZUU1YwHqHNzjxbNbYjb%2Fimage.png?alt=media&#x26;token=785909bc-683e-46d5-8da3-cb792aee96ff" alt=""><figcaption><p>Fig2: Create new allocation</p></figcaption></figure>

3. Now add blobbers and Click on "Confirm" to add blobbers. Review and confirm the details and pay from the existing balance. Create an allocation and the S3 server setup will open automatically. You will have to create your server instance by adding IP address.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FlSKwPgKzBwXqUgnCBzEd%2Fimage.png?alt=media&#x26;token=c2e78329-5d65-427a-9959-ab8bd7654582" alt=""><figcaption><p>Fig3: Server setup</p></figcaption></figure>

4. You need to obtain the IP address of your server, which can be provided by your hosting provider or retrieved using the `ifconfig` command in the terminal. For example, in the server logs, you may see an IP address such as `65.109.152.43`.&#x20;

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FYM1CbUmFX0RlI04i9yCs%2Fimage.png?alt=media&#x26;token=24fea28c-8abd-45f8-bbae-2493e013d4dd" alt=""><figcaption><p>Fig4: IP Address</p></figcaption></figure>

5. Now add your IP address and click on generate script in Blimp UI. Then enter the password for S3 deployment.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FpMGvKUCTbu1QRlU9hELl%2Fimage.png?alt=media&#x26;token=c4f254b2-b14d-4b98-80f0-ab0c299be654" alt=""><figcaption><p>Fig5: S3 Server Setup</p></figcaption></figure>

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FkIfGuPe4RNbu5jCkR3cM%2Fimage.png?alt=media&#x26;token=ec631306-35d7-43e0-a718-e2bcd7dfacf6" alt=""><figcaption><p>Fig6: S3 deployment password</p></figcaption></figure>

6. Now copy the script and run it in your server terminal.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FfhgqL3qGC2w31NTTfB7Z%2Fimage.png?alt=media&#x26;token=c5790481-2dee-4a45-9152-5d95551d107a" alt=""><figcaption><p>Fig7: Copy Script</p></figcaption></figure>

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2Fw2S41Ng6qxhRYlpardDz%2Fimage.png?alt=media&#x26;token=df891fce-d148-4a8e-b0ef-7ff590438537" alt=""><figcaption><p>Fig8: Run Script</p></figcaption></figure>

### Step 2: Deploy ZS3Server2

1. Go to "Standard Allocation" in the Blimp UI. Create a new allocation and name it `allocation22`.&#x20;

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FGZnAHJFzcbdQ1WZqxHNk%2Fimage.png?alt=media&#x26;token=cfda9a81-2521-4500-a76a-ef4748740fe4" alt=""><figcaption><p>Fig9: Create new standard allocation</p></figcaption></figure>

2. Click on "Confirm" and select the blobbers, then confirm again. This will create a standard allocation.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2Fajbn1ti5FWW14N2HswFe%2Fimage.png?alt=media&#x26;token=5af4ce3c-1d30-4c22-be3c-198dac368d85" alt=""><figcaption><p>Fig9: Confirm Details </p></figcaption></figure>

3. In the Blimp UI, copy the newly created standard allocation ID.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FsTY1no0komPHNpeL3xPr%2Fimage.png?alt=media&#x26;token=898ff88a-3684-4fd8-9cce-c5c6b0f4259d" alt=""><figcaption><p>Fig10: Copy Standard Allocation ID</p></figcaption></figure>

4. Go to your server, create a new `.zcn2` folder in your home directory (`$HOME`), and navigate to the `blimp` folder. Inside the `blimp` folder, create the `allocation.txt` file and paste the allocation ID.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FQmGXMvxrDu4KUw1JlozI%2Fimage.png?alt=media&#x26;token=34e2b5b4-8c53-4b3f-a8b7-a144da5b5cb7" alt=""><figcaption><p>Fig11: Paste allocation ID</p></figcaption></figure>

5. Copy the `docker-compose.yml`, `config.yaml`, `wallet.json` and `z3server.json` files from the `.zcn` folder to the `.zcn2` folder.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FFLSKNE5Fg530Ch4PI0uP%2Fimage.png?alt=media&#x26;token=c3a73ee7-ded7-45ad-9ffb-45cab4ac7b4b" alt=""><figcaption><p>Fig12: Copy wallet.json</p></figcaption></figure>

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2Fy1QV7uHRhVDuKz23S9qs%2Fimage.png?alt=media&#x26;token=0cf59a47-bbad-4140-96ba-e2fd31c7cd50" alt=""><figcaption><p>Fig 13: Copy z3server.json</p></figcaption></figure>

7. Edit the ports in `docker-compose.yml.`Go to line 55 in the `.zcn2/docker-compose.yml` file and note the ports `9002:9000`. Copy these ports to the `.zcn/docker-compose.yml` file.&#x20;

   \
   Now run the following commands to start the Docker containers for `.zcn2` folder defined in the `docker-compose.yml`:

   ```
   cd ~/.zcn2/
   docker-compose up -d
   ```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FuEKdaTWR0cwRgl6QhJ9V%2Fimage.png?alt=media&#x26;token=e0e0e7f3-eda4-4254-81fc-2012106af41e" alt=""><figcaption><p>Fig14: Copy Ports</p></figcaption></figure>

* Change the first port in `.zcn` from `9002` to `9000` in docker-compose.yml file, making it `9000:9000`.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FS3E7oMgAJ1MxsQAnCbRe%2Fimage.png?alt=media&#x26;token=fdbbcc69-3e11-450b-90be-467e2f420f9d" alt=""><figcaption><p>Fig15: Paste ports</p></figcaption></figure>

Now run the following commands to start the Docker containers defined in the `docker-compose.yml`:

```
cd ~/.zcn/
docker-compose up -d
```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2F6nC5fJGI07KE80sI0aTI%2Fimage.png?alt=media&#x26;token=2242524d-13c8-4b14-9fa8-f843e447beff" alt=""><figcaption><p>Fig16: Run commands</p></figcaption></figure>

### Step 3: Install MinIO Client (mc)

Follow the installation guide provided in the [ZS3Server documentation](https://min.io/docs/minio/linux/index.html#procedure).

#### 1. macOS **Homebrew**

Install mc packages using [Homebrew](http://brew.sh/)

```
brew install minio/stable/mc
mc --help
```

#### 2. GNU/Linux

**Binary Download**

| Platform    | Architecture | URL                                                    |
| ----------- | ------------ | ------------------------------------------------------ |
| GNU/Linux   | 64-bit Intel | <https://dl.min.io/client/mc/release/linux-amd64/mc>   |
| GNU/Linux   | 64-bit PPC   | <https://dl.min.io/client/mc/release/linux-ppc64le/mc> |
| GNU/Linux   | 64-bit ARM   | <https://dl.min.io/client/mc/release/linux-arm64/mc>   |
| Linux/s390x | S390X        | <https://dl.min.io/client/mc/release/linux-s390x/mc>   |

```
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
./mc --help
```

#### 3. Microsoft Windows

**Binary Download**

<table><thead><tr><th width="246">Platform</th><th>Architecture</th><th>URL</th></tr></thead><tbody><tr><td>Microsoft Windows</td><td>64-bit Intel</td><td><a href="https://dl.min.io/client/mc/release/windows-amd64/mc.exe">https://dl.min.io/client/mc/release/windows-amd64/mc.exe</a></td></tr></tbody></table>

```
mc.exe --help
```

### Step 4: Create Alias for ZS3Server1

Run the following command to create an alias for `zs3server1`:

```
mc alias set zs3server1 http://65.109.152.43:9000 shahnawaz rootroot --api S3v2
```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FaalYnssIIDijEIDNQKlg%2Fimage.png?alt=media&#x26;token=a5db08fa-cff8-4d3a-9e0f-2f636df4eddf" alt=""><figcaption><p>Fig17: Create Alias for ZS3Server1</p></figcaption></figure>

### Step 5: Create Alias for ZS3Server2

Run the following command to create an alias for `zs3server2`:

```
mc alias set zs3server2 http://65.109.152.43:9002 shahnawaz rootroot --api S3v2
```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2Ft0i9msvGXyovAr2cJglN%2Fimage.png?alt=media&#x26;token=42683e42-fed8-48c2-a21a-92b644ca0bbf" alt=""><figcaption><p>Fig18: Create Alias for ZS3Server2</p></figcaption></figure>

### Step 6: Create Bucket and Copy Data in ZS3Server1

1. Create a bucket in `zs3server1` with `allocation21`:

   ```
   mc mb zs3server1/allocation21
   ```
2. Verify the bucket:

   ```
   mc ls zs3server1
   ```
3. Copy data to the created bucket:

   ```
   mc cp ./ zs3server1/allocation21
   ```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2Fuu7X2zaUbnJpJb5fsnjO%2Fimage.png?alt=media&#x26;token=a642923f-deaa-4a56-a96d-d3452594c29a" alt=""><figcaption><p>Fig19: Create bucker and copy data for ZS3Server1</p></figcaption></figure>

### Step 7: Create Bucket and Copy Data in ZS3Server2

1. Create a bucket in `zs3server2` with `allocation22`:

   ```
   mc mb zs3server2/allocation22
   ```
2. Verify the bucket:

   ```
   mc ls zs3server2
   ```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2F9fj22VHF49LF62cTjKNO%2Fimage.png?alt=media&#x26;token=351bed67-45d0-45c3-b224-6b8642e89c37" alt=""><figcaption><p>Fig20: Create bucker and copy data for ZS3Server1</p></figcaption></figure>

### Step 8: Set Up Replication

Run the following command to create replication between the buckets:

```
mc mirror zs3server1/allocation21/ zs3server2/allocation22/ --remove watch
```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FyiStXvnjj9KDv1cMrnUM%2Fimage.png?alt=media&#x26;token=80930a7a-d464-4e20-907b-bea5078436b4" alt=""><figcaption><p>Fig21 : Set up allocation</p></figcaption></figure>

Any deletions in `bucket1` will automatically replicate in `bucket2`.

### Step 9: Perform Disaster Recovery

1. Shut down `zs3server1` and clean up its deployment.
2. Create a new allocation (`allocation23`) using the Blimp UI with a standard allocation.
3. Update the `allocation.txt` file in `.zcn` with the new `allocation23` ID.
4. Set up an alias for the new server:

   ```
   mc alias set zs3server3 http://65.109.152.43:9000 shahnawaz rootroot --api S3v2
   ```
5. Create a new bucket:

   ```
   mc mb zs3server3/allocation23
   ```
6. Restore data to the new allocation:

   ```
   mc mirror zs3server2/allocation22/ zs3server3/allocation23/
   ```

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2Fhc4qvrt3fS3QhO5LahK2%2Fimage.png?alt=media&#x26;token=7cb15442-d775-4e26-835c-170cd540f15b" alt=""><figcaption><p>Fig22: Perform Disaster Recover</p></figcaption></figure>

### Step 10: Verify Recovery

Check that the files have been recovered to the new allocation:

```
mc ls zs3server3/allocation3
```

***

## Replication

This section outlines the steps to set up replication between two ZS3Servers.&#x20;

Replication ensures that data from one server is mirrored to another for backup and redundancy.&#x20;

Follow the steps below to configure and initiate replication.

{% embed url="<https://drive.google.com/file/d/1Vjw3b2HqWGTT-PDVIdMYJ4e2iVYHTPms/view?usp=drive_link>" %}
Replication Video Tutorial
{% endembed %}

### Prerequisites

* For running two ZS3Servers on the same machine:
  * Copy the contents of the `.zcn` folder to `.zcn2`.
  * Update `allocation.txt` and `zs3server.json` in `.zcn2`.
  * Update the `docker-compose.yml` file to use unique ports.
* Ensure both ZS3Servers are configured using MinIO Client aliases:
  * Alias for the first server (`zcn`):

    ```bash
    mc alias set primary http://<HOST_IP>:9000 root root --api S3v2
    ```
  * Alias for the second server (`zcn2`):

    ```bash
    mc alias set secondary http://<HOST_IP>:9002 root root --api S3v2
    ```

### Step 1: Verify Configuration

1. Navigate to the `.zcn2` folder:

   ```bash
   cd .zcn2/
   ```
2. Open the terminal and run:

   ```bash
   ls
   cat docker-compose.yml
   ```

   * Verify the ports are correctly set to `9002:9000`.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FJOKcSCBkU0nwrK85yOi8%2Fimage.png?alt=media&#x26;token=95d7b341-d6c8-48dd-94f3-9b7d0322b9a4" alt=""><figcaption><p>Fig23: Verify Ports</p></figcaption></figure>

3. Check the standard allocation ID:

```bash
cat blimp/allocation.txt
```

* Compare this ID with the allocation ID in the Blimp dashboard to ensure consistency.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FldNedA3Lz6jKSi2IwHKn%2Fimage.png?alt=media&#x26;token=dc769e64-e35f-468a-be3a-bfc2e995a4f7" alt=""><figcaption><p>Fig24: Check Allocation ID</p></figcaption></figure>

### Step 2: Configure Aliases

1. Use the MinIO Client (mc) to configure aliases for both servers:

**Format**:

```bash
mc alias set primary http://<HOST_IP>:9000 miniouser miniopassword --api S3v2
mc alias set secondary http://<HOST_IP>:9002 miniouser miniopassword --api S3v2
```

**Example**:

```bash
mc alias set primary http://65.109.152.43:9000 root root --api S3v2
mc alias set secondary http://65.109.152.43:9002 root root --api S3v2
```

2. Run the alias commands:

```bash
mc alias set .zcn http://<HOST_IP>:9000 root root --api S3v2
mc alias set .zcn2 http://<HOST_IP>:9002 root root --api S3v2
```

### Step 3: Initiate Replication

1. Use the following command to start replication:

   ```bash
   ./mc mirror primary/<BUCKET_PREFIX>/ secondary/<BUCKET_PREFIX>/ --remove --watch
   ```

   * Replace `<BUCKET_PREFIX>` with the appropriate bucket names.
2. Example:

   ```bash
   ./mc mirror zcn/test2-s3/ zcn2/mbtest2 --remove --watch
   ```

* `test2-s3` is a folder in the S3 allocation.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FKNHecFlqNzcGAL9omFA8%2Fimage.png?alt=media&#x26;token=a5b6a8fb-9308-4945-b279-de83544d6998" alt=""><figcaption><p>Fig25: test2-s3</p></figcaption></figure>

* `mbtest2` will be created in the standard allocation on `zcn2`.

<figure><img src="https://2414485336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUGN3Vu2Hi1voQQLrIVGO%2Fuploads%2FT2XRZeV8LpgHBQlPRJvK%2Fimage.png?alt=media&#x26;token=7bbbff83-7c73-4049-bd5a-4c03f698f3e1" alt=""><figcaption><p>Fig26: mbtest2</p></figcaption></figure>

* All data from `test2-s3` will be replicated into `mbtest2`.

### Step 4: Verify Replication

1. Check the contents of the buckets:

   ```bash
   mc ls zcn
   mc ls zcn2
   ```
2. Create new buckets if necessary:

   ```bash
   mc mb zcn/test2-s3
   mc mb zcn2/mbtest2
   ```
3. Confirm that the data is mirrored correctly:

```bash
./mc mirror zcn/test2-s3/ zcn2/mbtest2 --remove --watch
```

## Backup and Restore with Restic

Use [Restic](https://restic.net/) for lightweight, versioned, and secure backups to your ZS3 bucket.

### Step 1: Install Restic

```
sudo apt update -y
sudo apt install restic -y
sudo restic self-update
```

### Step 2: Set Environment Variables

```
export AWS_ACCESS_KEY_ID=<ACCESS_KEY>
export AWS_SECRET_ACCESS_KEY=<SECRET_KEY>
export RESTIC_REPOSITORY="s3:<ZS3_URL>"
```

### Step 3: Initialize the Repository

```
restic init
```

### Step 4: Run a Backup

```
restic -r s3:<ZS3_URL> --verbose backup <path-to-directory-to-backup>
```

### Step 5: List Snapshots

```
restic snapshots
```

### Step 6: Restore Snapshot

```
restic restore latest --target ~/ --verbose
```

### Step 7: Automate via Crontab (Optional)

Use `crontab -e` to add periodic backup jobs.
