Post

Backing up files with rclone

Overview

Rclone is a tool I recently discovered that allows you to sync files to cloud-based storage. You are not limited to a single cloud destination, either. This guide is focused on installing and configuring rclone for a VPS, such as Linode or DigitalOcean.

Setup

This guide was written using a Debian 8 (jessie) install.

  1. Download rclone for your distro from their website.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
     $ wget http://downloads.rclone.org/rclone-current-linux-amd64.zip
     --2016-07-23 12:50:50--  http://downloads.rclone.org/rclone-current-linux-amd64.zip
     Resolving downloads.rclone.org (downloads.rclone.org)... 77.73.5.145
     Connecting to downloads.rclone.org (downloads.rclone.org)|77.73.5.145|:80... connected.
     HTTP request sent, awaiting response... 200 OK
     Length: 3672060 (3.5M) [application/zip]
     Saving to: ‘rclone-current-linux-amd64.zip’
    
     rclone-current-linux-amd64.zip                    100%[============================================================================================================>]   3.50M  3.50MB/s   in 1.0s
    
     2016-07-23 12:50:52 (3.50 MB/s) - ‘rclone-current-linux-amd64.zip’ saved [3672060/3672060]
    
  2. The creator recommends moving the binary into /usr/sbin

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
     unzip rclone-v1.17-linux-amd64.zip
     cd rclone-v1.17-linux-amd64
     #copy binary file
     sudo cp rclone /usr/sbin/
     sudo chown root:root /usr/sbin/rclone
     sudo chmod 755 /usr/sbin/rclone
     #install manpage
     sudo mkdir -p /usr/local/share/man/man1
     sudo cp rclone.1 /usr/local/share/man/man1/
     sudo mandb
    
  3. Next, configure rclone with the storage system of your choice. Rclone supports quite a few cloud systems, visit the overview page to find the one that is best for you.

  4. I chose Google Drive to start, as Sync was not on the list.

    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    
     $ ./rclone config
     2016/07/23 12:54:21 Failed to load config file "/home/kris/.rclone.conf" - using defaults: open /home/kris/.rclone.conf: no such file or directory
     No remotes found - make a new one
     n) New remote
     s) Set configuration password
     q) Quit config
     n/s/q> n
     name> gdrive
     Type of storage to configure.
     Choose a number from below, or type in your own value
      1 / Amazon Drive
        \ "amazon cloud drive"
      2 / Amazon S3 (also Dreamhost, Ceph, Minio)
        \ "s3"
      3 / Backblaze B2
        \ "b2"
      4 / Dropbox
        \ "dropbox"
      5 / Google Cloud Storage (this is not Google Drive)
        \ "google cloud storage"
      6 / Google Drive
        \ "drive"
      7 / Hubic
        \ "hubic"
      8 / Local Disk
        \ "local"
      9 / Microsoft OneDrive
        \ "onedrive"
     10 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
        \ "swift"
     11 / Yandex Disk
        \ "yandex"
     Storage> 6
     Google Application Client Id - leave blank normally.
     client_id>
     Google Application Client Secret - leave blank normally.
     client_secret>
     Remote config
     Use auto config?
      * Say Y if not sure
      * Say N if you are working on a remote or headless machine or Y didn't work
     y) Yes
     n) No
     y/n> y
     If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
     Log in and authorize rclone for access
     Waiting for code...
     Got code
     --------------------
     [gdrive]
     client_id =
     client_secret =
     token = {"access_token":"some_text"}
     --------------------
     y) Yes this is OK
     e) Edit this remote
     d) Delete this remote
     y/e/d> y
     Current remotes:
    
     Name                 Type
     ====                 ====
     gdrive               drive
    
     e) Edit existing remote
     n) New remote
     d) Delete remote
     s) Set configuration password
     q) Quit config
     e/n/d/s/q> q
    
  5. Note, I added an iptables NAT rule and edited a sysctl to authorize rclone to my Google Account from my local machine.

    1
    2
    3
    4
    
     $ sudo sysctl -w net.ipv4.conf.eth0.route_localnet=1
     net.ipv4.conf.eth0.route_localnet = 1
    
     $ iptables -t nat -I PREROUTING -p tcp -d <ip> --dport 53682 -j DNAT --to-destination 127.0.0.1:53682
    
  6. Once setup is complete, it’s a good idea to revert the sysctl edited earlier.

    1
    2
    
     $ sudo sysctl -w net.ipv4.conf.eth0.route_localnet=0
     net.ipv4.conf.eth0.route_localnet = 0
    
  7. Review the usage documentation to familiarize yourself with the rclone syntax. In my case, I want to sync a local directory that is populated by a script that makes database backups nightly. In the future, I plan to add this as a final step to a script so offsite backups are performed automatically.

Conclusion:

Rclone is an awesome and easy to setup tool to give you peace of mind that your files are backed up. Happy cloning!

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

Comments powered by Disqus.

© Kris Crawford. Some rights reserved.

Using the Chirpy theme for Jekyll.