Skip to content

Instantly share code, notes, and snippets.

@jimlambie
Last active September 20, 2018 11:39
Show Gist options
  • Save jimlambie/e3920aae5ddc2860b111d413dba96d6a to your computer and use it in GitHub Desktop.
Save jimlambie/e3920aae5ddc2860b111d413dba96d6a to your computer and use it in GitHub Desktop.

Local computer

  1. Make new directory and change into it
~ $ mkdir my-files
~ $ cd my-files
  1. Add a new file to the directory
~/my-files $ echo "It was a dark and stormy night..." > memoir.txt
  1. Create dat from the directory and share it
~/my-files $ dat share

dat v13.11.4
Created new dat in /Users/james/my-files/.dat
dat://65bf19952067c4bb55769d8a9053835d840dddaee062c8c53a4c9b68b5d8adee
Sharing dat: 1 files (34 B)

0 connections | Download 0 B/s Upload 0 B/s

Watching for file updates
  1. This is now watching the directory, so adding another file in will cause the dat to be updated and rebroadcast

Remote server

  1. Create directory to store the dat archive
~ $ mkdir my-files-clone
~ $ cd my-files-clone
  1. Create "feeds" file listing out the dat links the archiver should automatically update
~/my-files-clone $ echo "dat://65bf19952067c4bb55769d8a9053835d840dddaee062c8c53a4c9b68b5d8adee" > feeds
  1. Run hypercored
~/my-files-clone $ hypercored

Watching /home/ubuntu/my-files-clone/feeds for a list of active feeds
Swarm listening on port 3282
Archiver key is 3bee06faee91d7b8356cb893729aa66b1b43fc87bd0231767c5c28164dd540c8
Adding 65bf19952067c4bb55769d8a9053835d840dddaee062c8c53a4c9b68b5d8adee
  1. This synchronises the dat to the server, and will create the following directory structure:
ubuntu@ip-172-31-26-100:~/my-files-clone $ ll
total 16
drwxrwxr-x  3 ubuntu ubuntu 4096 Sep 20 08:04 ./
drwxr-xr-x 18 ubuntu ubuntu 4096 Sep 20 08:04 ../
drwxrwxr-x  4 ubuntu ubuntu 4096 Sep 20 08:04 archiver/
-rw-rw-r--  1 ubuntu ubuntu   71 Sep 20 08:04 feeds

What happens now?!

The server is now continually updating it's own copy of the files discovered in the dat, which means if the files on your local computer are lost, then there is still a copy available.

Test this by going to the datbase site using the dat link that you got at the beginning in step 3:

https://datbase.org/view?query=dat://65bf19952067c4bb55769d8a9053835d840dddaee062c8c53a4c9b68b5d8adee

This page should load the files that are in your directory, and if both local and remote are running then it should display "2 sources available".

Now, if you stop the dat share on the local computer, and even delete the local directory (rm -rf my-files), then the datbase site should display "1 source available", because the server is still running and serving a clone of the original directory.

Note: before deleting the local directory, try adding another file to it and refreshing the datbase site to show that the new file was broadcast.

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