Home Rclone
Post
Cancel

Rclone

Rclone allows file backups, like rsync, but supports a variety of backup destinations (called remotes), for example cloud providers like OneDrive or DropBox. Configuration is straight forward, but gets a little finicky when you have to configure access to cloud providers - Especially if your host is running headless. Because of this, I’ve created a main backup server that is the only one that needs to connect to the cloud remote. Using a basic samba share that all my other clients and servers can backup to, the configuration for several backup clients becomes far easier.

Syntax

rclone supports move, copy, sync, mount, and many other operations. Whilie the syntax is the same, there are inherit differences (and --flags) For instance sync could delete a file present in the remote that is no longer in the source.

1
rclone <move|copy|sync|mount|ls> <options> <source> <remote>:<path/on/remote>

Configuring remotes

Setting up an rclone remote to an SMB share is very straight forward and can easily be automated.

Example Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/bash

# Install rclone (or check other installation options at https://rclone.org/)
# sudo apt install unzip -y
# sudo -v ; curl https://rclone.org/install.sh | sudo bash
rcloneBin=$(which rclone)
unzipBin=$(which unzip)

### Variables for Remote
ruser="" # Username configured for the SMB server
rname="" # Hostname of SMB server
rdomain="" # Domain of SMB server
rhost="$rname.$rdomain" # Set this to the SMB server's IP if its FQDN doesn't resolve

# Prompt for password (can be set manually prior to running script)
if [ ! -v "$clonePass" ]; then
        echo "Password variable for remote share  not found."
        read -p "Enter Password: " pw
        export clonePass="$pw"
elif [ "$clonePass"="" ]; then
        echo "Password variable is empty."
        read -p "Enter Password: " pw
        export clonePass="$pw"
fi

rclone config create "$rname" smb user="$ruser" host="$rhost" pass="$clonePass" domain="$rdomain" --obscure

unset clonePass
echo "Password variable unset. Rclone config complete."

Rclone sync

Example Scripts

Local Backup

1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/bash

includeFile="./include.conf"
dstPath="$HOME/$(echo $HOSTNAME)_config/"

# Read from include.conf and verify that files exist
if [ ! -f "$includeFile" ]; then
    exit 0
fi

rclone sync --filter-from "$includeFile" / "$dstPath"

Remote backup

1
2
3
4
5
6
7
#!/usr/bin/bash

# Script to run on backup client
srcDir="$(echo "$HOSTNAME"_config)"
dstDir="remote:/shareName/backup/$srcDir/"

rclone sync "$HOME/$srcDir" "$dstDir"

Filtering

Using a predefined list of files to back up, there’s only one (well two, because windows clients) places you need to edit to add/remove entries The file is read from top to bottom. This means that if a directory excluded on line 1, it will not be included if a file or subdirectory is specifically included further down.

Worth noting is that any file path is relative to the specified source path in the rsync command, and that any leading / is stripped When running rclone sync --filter-from "$includeFile" /home/username/ remote:Path/Destination/ with the exampe filter below, rclone will look for /home/username/home/**/.config and /home/username/etc/hosts etc.

Filter file example

# Root
+ home/**/.config/
+ home/**/.bashrc
# Configs in etc
+ etc/network/interfaces
+ etc/hosts
+ etc/samba/smb.conf
# Exclude everything else
- *

Testing

Use --dry-run for testing changes and -vvv to be overrun by the output

This post is licensed under CC BY 4.0 by the author.
Trending Tags
Contents
Trending Tags