rclone.org 1
Nick Craig-Wood
Go London User Group - 21st November 2018
- Rclone “rsync for cloud storage”
– https://rclone.org – https://github.com/ncw/rclone
- Talk by
– Nick Craig-Wood – T
witter: @njcw
– Email: nick@craig-wood.com
Go London User Group - 21 st November 2018 Rclone rsync for cloud - - PowerPoint PPT Presentation
Go London User Group - 21 st November 2018 Rclone rsync for cloud storage https://rclone.org https://github.com/ncw/rclone Talk by Nick Craig-Wood T witter: @njcw Email: nick@craig-wood.com 1 rclone.org Nick
rclone.org 1
Nick Craig-Wood
Go London User Group - 21st November 2018
– https://rclone.org – https://github.com/ncw/rclone
– Nick Craig-Wood – T
witter: @njcw
– Email: nick@craig-wood.com
rclone.org 2
Nick Craig-Wood
About me
– CTO of Memset Ltd by day – Open Source coder by night – Keen interest in storage, data integrity – Reformed data hoarder (ha!)
rclone.org 3
Nick Craig-Wood
Contents
rclone.org 4
Nick Craig-Wood
Rclone - “rsync for cloud storage”
and from cloud providers
rclone.org 5
Nick Craig-Wood
Rclone vs Rsync
and synchronizing fjles across computer systems, by checking the timestamp and size
and functions as both a fjle synchronization and fjle transfer program.
encoding, and is used for minimizing network usage.
From Wikipedia
rclone.org 6
Nick Craig-Wood
Cloud providers supported by rclone
rclone.org 7
Nick Craig-Wood
Rclone platforms
I ♥ Cross Compilation CPU OS
rclone.org 8
Nick Craig-Wood
How rclone came to be
exercise
– github.com/ncw/swift – originally was “swiftsync”
– Go 1.0 – 3 backends
rclone.org 9
Nick Craig-Wood
Why Go?
pick up
rclone.org 10
Nick Craig-Wood
One tool to rule them all
– 11,000 stars on Github – 200 contributors – 500 pull requests – 1,500 issues – 250,000 downloads a month – Packaged in Ubuntu, Arch, Debian,
Homebrew, Chocolatey and more
rclone.org 11
Nick Craig-Wood
Visualising Rclone’s History
rclone.org 12
Nick Craig-Wood
Rclone becomes popular and breaks Amazon Cloud Drive
?
rclone.org 13
Nick Craig-Wood
Rclone verbs – bigger = more popular
rclone.org 14
Nick Craig-Wood
rclone confjg - Confjg Wizard
Confjg Wizard
– T
ext based
– Easy to use – Not pretty – Calls your
browser to do
rclone.org 15
Nick Craig-Wood
rclone copy - demo
– Copy new fjles
to destination
– Don’t delete
fjles from destination
– Your go to
rclone command!
rclone.org 16
Nick Craig-Wood
rclone sync - demo
– Copy new fjles
to destination
– Delete
destination fjles not in source
– Use with –dry-
run fjrst recommended
rclone.org 18
Nick Craig-Wood
rclone copy “Source Dir” “Dest Dir”
File 1 Source Dir File 2 File 3 Destination Before Source Before Actions File 1 Source Dir File 2 File 3 Dest Dir File 2 File 3 Destination After Source After File 1 Destination includes Source File 4 Dest Dir File 2 Old File 3 Copied Not T
Overwritten Not T
File 4
rclone.org 19
Nick Craig-Wood
rclone sync “Source Dir” “Dest Dir”
File 1 Source Dir File 2 File 3 Destination Before Source Before Actions File 1 Source Dir File 2 File 3 Dest Dir File 2 File 3 Destination After Source After File 1 Destination identical to Source File 4 Dest Dir File 2 Old File 3 Copied Not T
Overwritten Deleted
rclone.org 21
Nick Craig-Wood
rclone mount remote:path /mount/point
– Linux, macOS, FreeBSD – Windows va WinFSP
– Needed as can’t write to
middle of object
– Or read and write together
rclone.org 22
Nick Craig-Wood
rclone ncdu
This displays a text based user interface allowing the navigation of a Remote. It is most useful for answering the question: What is using all my disk space?
rclone.org 23
Nick Craig-Wood
Backend interface
rclone.org 24
Nick Craig-Wood
Object interface
rclone.org 25
Nick Craig-Wood
Optional interfaces for Fs
rclone.org 26
Nick Craig-Wood
Using an optional interface
–
Do a type assertion for the interface to see if it exists.
–
But what if this is a wrapper backend wrapping a backend that doesn’t support Purge?
–
And if we need to know in advance?...
rclone.org 27
Nick Craig-Wood
The solution
rclone.org 28
Nick Craig-Wood
T esting
– 27 backends – x 50 commands – x 8 OSes – x 6 CPU Architectures – x 4 Go versions?
– Some things are easy – Who wants to write mocks
for 27 difgerent cloud providers?
– Integration tests use go
test framework
– Run daily
rclone.org 29
Nick Craig-Wood
CI – Unit testing and build
– Runs all non
integration tests
– T
ests mount
– Builds for all – Makes binaries – Uploads to beta
release
Push Pull Request Push Pull Request
rclone.org 30
Nick Craig-Wood
Integration testing
– Run daily – T
run on every push
– Creates fancy
report
– Not integrated with
Github (yet)
Daily Pull Integration T est Server Subset of cloud providers At least one per backend FTP SFTP HTTP Crypt
rclone.org 31
Nick Craig-Wood
Integration tests
– Cloud providers aren’t
perfectly reliable
– Eventual consistency – Networking
– Retries, Retries, Retries – Lots of work getting it right
rclone.org 32
Nick Craig-Wood
Retrying integration tests
– Runs standard go tests – Runs lots of tests in parallel – Provides fmags as specifjed in a
confjg fjle
– Parses the output of the tests – Retries the just the failing tests – Should probably become an
right!
Attempt 1/5 ./operations.test
Attempt 2/5 ./operations.test
TestRmdirsNoLeaveRoot)$'
rclone.org 33
Nick Craig-Wood
Integration tests for backends
tests
– Easy to add thanks to
go1.6 nested tests
– Give a recipe to follow
when making a new backend
– Just make the
integration tests pass
– Originally done with
code gen pre go1.6
rclone.org 34
Nick Craig-Wood
Integration tests elsewhere
to tests
– Rclone uses this with
a “-remote” fmag to signal that the test should be done remotely
– There are other fmags
for debugging and more in depth tests
rclone.org 35
Nick Craig-Wood
Standing on the shoulders of giants
– 95,000 lines of code – 450 source fjles – Not including “vendor”
– 520,000 lines of code – 1,100 fjles – All stored in “vendor”
All build on top of the excellent standard library
rclone.org 36
Nick Craig-Wood
Favourite libraries and tools: golang.org/x/tools/cmd/goimports
– Get it in your editor –
never type an import statement again
– Run it as a save hook –
it will `go fmt` your code too
rclone.org 37
Nick Craig-Wood
github.com/spf13/cobra
rclone.org 38
Nick Craig-Wood
Documentation with github.com/spf13/cobra
Go code defjnes help… …becomes -h output… …and markdown for web.
rclone.org 39
Nick Craig-Wood
github.com/pkg/errors
this
– “unexpected EOF”
– “NewFs creating
backend: couldn’t connect SSH: unexpected EOF”
rclone.org 40
Nick Craig-Wood
What to do if your open source project takes ofg...
is good)
an issue for help
contributors
docs
Rclone Star History
Front Page of Hacker News
rclone.org 41
Nick Craig-Wood
Thank you for listening
– https://rclone.org – https://github.com/ncw/rclone
– Nick Craig-Wood – T
witter: @njcw
– Email: nick@craig-wood.com
– Gource – source code history visualisation – Asciinema and asciicast2gif – terminal GIFs