Skip to content

Instantly share code, notes, and snippets.

@zoonderkins
Last active March 21, 2022 07:01
Show Gist options
  • Save zoonderkins/7e1094b729703aadfee44bd5ce68b383 to your computer and use it in GitHub Desktop.
Save zoonderkins/7e1094b729703aadfee44bd5ce68b383 to your computer and use it in GitHub Desktop.
Secure your NextCloud with Kopia with backup

Kopia with Rclone backup to backblaze B2 Cloud

Step 1

kopia repository create rclone --remote-path b2:/de3-backup/jp3-web-kopia

Enter password to create new repository:
Re-enter password for verification:
Initializing repository with:
  block hash:          BLAKE2B-256-128
  encryption:          AES256-GCM-HMAC-SHA256
  splitter:            DYNAMIC-4M-BUZHASH
Connected to repository.

NOTICE: Kopia will check for updates on GitHub every 7 days, starting 24 hours after first use.
To disable this behavior, set environment variable KOPIA_CHECK_FOR_UPDATES=false
Alternatively you can remove the file "/root/.config/kopia/repository.config.update-info.json".

Retention:
  Annual snapshots:     3   (defined for this target)
  Monthly snapshots:   24   (defined for this target)
  Weekly snapshots:     4   (defined for this target)
  Daily snapshots:      7   (defined for this target)
  Hourly snapshots:    48   (defined for this target)
  Latest snapshots:    10   (defined for this target)
Compression disabled.

To find more information about default policy run 'kopia policy get'.
To change the policy use 'kopia policy set' command.

Step 2 do a validation

kopia repository validate-provider

Validating blob list responses
Validating non-existent blob responses
Writing blob (5000000 bytes)
Validating conditional creates...
Validating list responses...
Validating partial reads...
Validating full reads...
Validating metadata...
Running concurrency test for 30s...
All good.
Cleaning up temporary data...

Connect to remote repository

kopia repository connect rclone --remote-path b2:/de3-backup/jp3-web-kopia

Kopia create snapshot

kopia snapshot create /data/wwwroot
kopia snapshot create /data/backup

Install Rclone, Kopia,

# Install Kopia
curl -s https://kopia.io/signing-key | sudo gpg --dearmor -o /usr/share/keyrings/kopia-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/kopia-keyring.gpg] http://packages.kopia.io/apt/ stable main" | sudo tee /etc/apt/sources.list.d/kopia.list

sudo apt update -y 
sudo apt install kopia fuse

# Install rclone
curl https://rclone.org/install.sh | sudo bash

Mount your remote storage drive ( Im using Hetzner Storage box webdav )

# Mount rclone when system boot

### Mkdir storage directory
mkdir /mnt/de1-storage

### /etc/rc.local
#!/bin/bash
rclone mount --vfs-cache-mode writes de1-storage: /mnt/de1-storage --daemon --allow-non-empty

Try copy file to storage box

# Download fake file
wget https://lg.vie.alwyzon.net/1GB.test

# Test upload
rclone copy 1GB.test de1-storage:/ --progress
Transferred:   	        1 GiB / 1 GiB, 100%, 102.880 MiB/s, ETA 0s
Transferred:            1 / 1, 100%
Elapsed time:        10.0s

Kopia create repository

kopia repository create filesystem --path /root/kopia-local/

Enter password to create new repository: xxxxxx
Re-enter password for verification: xxxxx

Initializing repository with:
  block hash:          BLAKE2B-256-128
  encryption:          AES256-GCM-HMAC-SHA256
  splitter:            DYNAMIC-4M-BUZHASH
Connected to repository.
NOTICE: Kopia will check for updates on GitHub every 7 days, starting 24 hours after first use.
To disable this behavior, set environment variable KOPIA_CHECK_FOR_UPDATES=false
Alternatively you can remove the file "/root/.config/kopia/repository.config.update-info.json".

Retention:
  Annual snapshots:     3   (defined for this target)
  Monthly snapshots:   24   (defined for this target)
  Weekly snapshots:     4   (defined for this target)
  Daily snapshots:      7   (defined for this target)
  Hourly snapshots:    48   (defined for this target)
  Latest snapshots:    10   (defined for this target)
Compression disabled.

To find more information about default policy run 'kopia policy get'.

Verify remote repository is compatiable with Kopia

kopia repository validate-provider

Connect to Kopia repository

kopia repository connect filesystem --path /root/kopia-local/
Enter password to open repository: xxxxx

Connected to repository.

Create Kopia snapshot to backup Nextcloud

# mkdir /mnt/kopia-local
kopia snapshot create /root/nextcloud/

# Also make it run cronjob everynight

Rclone sync kopia local repository to Storagebox, BackBlaze B2 or Storj

rclone sync /root/kopia-local/ de1-storage:/kopia-nextcloud -v -c

Just copy a file

rclone copy /root/backup-codeserver-* de1-storage:/jp4 -c -v

List snapshot

kopia snapshot list
root@at1:/root/nextcloud
  2022-03-13 10:00:11 UTC k68d41da6975a85c225c394411fd55a32 49.9 GB drwxr-xr-x files:40994 dirs:10404 errors:2 (latest-1,hourly-1,daily-1,weekly-1,monthly-1,annual-1)

Mount snapshot

kopia mount k68d41da6975a85c225c394411fd55a32 /mnt/tmp &

# Unmount
umount /mnt/tmp

Kopia ignore

kopia policy set --add-ignore node_modules/ .

cd /root/nextcloud/

[1]+  Done                    kopia mount k68d41da6975a85c225c394411fd55a32 /mnt/tmp  (wd: ~)
(wd now: ~/nextcloud)
root@at1:~/nextcloud# kopia policy set --add-ignore node_modules/ .
Setting policy for root@at1:/root/nextcloud
 - adding "node_modules/" to "ignore rules"

Kopia compression setup

https://kopia.io/docs/features/#compression

kopia policy set --global --compression=zstd

Kopia policy global setup

kopia policy set --global --keep-weekly=2
kopia policy set --global --keep-monthly=1
kopia policy set --global --keep-latest=2
kopia policy set --global --keep-hourly=1
kopia policy set --global --keep-daily=2

Kopia policy global review

kopia policy show --global
Policy for (global):

Retention:
  Annual snapshots:                   3   (defined for this target)
  Monthly snapshots:                  0   (defined for this target)
  Weekly snapshots:                   2   (defined for this target)
  Daily snapshots:                    1   (defined for this target)
  Hourly snapshots:                   0   (defined for this target)
  Latest snapshots:                   2   (defined for this target)

Files policy:
  Ignore cache directories:        true   (defined for this target)
  No ignore rules:
  Read ignore rules from files:           (defined for this target)
    .kopiaignore
  Scan one filesystem only:       false   (defined for this target)

Error handling policy:
  Ignore file read errors:        false   (defined for this target)
  Ignore directory read errors:   false   (defined for this target)
  Ignore unknown types:            true   (defined for this target)

Scheduling policy:
  Scheduled snapshots:
    None.
  Manual snapshot:                false   (defined for this target)

Compression disabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment