People are divided into those who make backups and those who will make them...
The above statement is as true as it is painful for those who have experienced the loss of data valuable to them. Backing up data should be an obvious thing not just for regular users, let alone people in the IT industry, i.e. administrators or programmers.
We can keep a backup on our local computer, but that's not the safest solution. Hard drives have a tendency to fail, and it's rare to have a RAID array at home. We could be robbed or simply lose data by losing the drive or the device storing the data. Not to mention accidentally deleting the contents of a disk or the activity of a computer virus.
We can always burn to other media (DVD, pendrive), but this solution isn't very convenient either.
If we don't need to make a backup of several dozen GB in size, free solutions like online drives placed in the increasingly popular "cloud" come to the rescue. Currently the most popular one is Dropbox, along with the increasingly popular solution from Google: Google Drive and from Microsoft: Sky Drive. I decided on Dropbox, mainly because of its cross-platform nature (including Linux/Mac/Windows/Android) and its good native console client.
What is Dropbox?
It's not just a typical online drive like ones that already appeared on the market before. Dropbox is a service for creating backups as well as synchronizing files and directories between multiple devices on which we've installed the appropriate client. Files and folders already synced to our account can be shared with friends by making individual files or entire directories public, generating a unique link as a result (a good way to get around mail attachment size limits).
A useful feature is also the ability to restore earlier versions of files. Among the more interesting things, there's also a photo gallery using Ajax technology.
The web interface is quite pleasant to use. It uses drag-and-drop technology, allowing files to be moved by dragging icons from the disk onto the browser. Dropbox's WebUI has implemented support for keyboard shortcuts, e.g. CTRL +A, CTRL +C, CTRL +V, and the keys: DELETE, F2, or ENTER.
Dropbox account capacity
At first, right after creating an account directly on the website, we get 2 GB of free space. You can do this using this LINK, thanks to which you'll get (me too) a bonus 500MB to start. Dropbox offers us several ways to increase our account's capacity, here they are:
- 3 GB - Camera Upload, i.e. automatically uploading photos from an external source (e.g. camera, phone, pendrive...). To use this option we need to have the desktop application. In short, we need to upload 3 GB of photos, after which we can delete them and enjoy the extra space. More details here: Camera Upload Dropbox
- 250 MB - we'll get this after completing the "getting started" tutorial
- 375 MB - for three actions related to Facebook, Twitter
- 125 MB - Tell us why you love Dropbox
- up to 16 GB! - 500 MB for every person who registers using our reflink
- ...so in total nearly 22 GB of free space
Installing Dropbox on Linux:
- Of course we need to already have a Dropbox account
- The first step will be to download the package matching our processor architecture:
#go to the home directory:
cd ~
# for 32bit:
wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -
for 64bit:
wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
Please visit https://www.dropbox.com/cli_link?host_id=1e6ee43b6519a6e4144621e8c8d48380 to link this machine.We need to log in via this link. Even if it's a remote machine, it doesn't matter which computer we log in from. After logging in successfully, we'll see a message and the directory ~/Dropbox will be created.
This computer is now linked to Dropbox. Welcome Dominik
#let's create a directory, e.g. drop:
mkdir -p ~/dorp
#we download the package:
wget -O ~/drop/dropbox.py "https://www.dropbox.com/download?dl=packages/dropbox.py"
#we make it executable:
chmod +x ~/drop/dropbox.py
Brief description of dropbox.py:
At first, I suggest checking the help: ~/drop/dropbox.py help
status get current status of the dropboxd
status gives the current status of dropboxd
help this one's probably clear
puburl displays the url of publicly shared files
stop stop dropboxd
running checks whether dropbox is running
start start dropboxd
filestatus current sync status of one or more files
ls displays the contents of a directory and its sync status
autostart run on login
exclude disable sync for directories
lansync enables or disables LAN mode
Backup and synchronization
The backup issue is dead simple. During installation, Dropbox creates the directory ~/Dropbox/, in which we place files, and they are automatically uploaded to Dropbox's servers. That's how it works on Windows; in the case of Linux there's no need to duplicate data already existing on the disk (although there are already programs for Windows thanks to which we don't have to copy everything into the Dropbox directory). In our case, symbolic links are enough, thanks to which we don't waste disk space, and at the same time another backup is much more convenient because there's no need to overwrite an already modified file.
Let's assume a situation where a user has this directory structure:
stuff/
|-- kat1
| `-- plik1.txt
|-- kat2
`-- kat3
|-- plik3.txt
`-- plik43.txt
To back up the stuff directory, we run dropbox and create a symbolic link:
ln -s /home/user/stuff /home/user/Dropbox
If it's a large amount of data, we can check the progress: ~/drop/dropbox.py status After a successful operation, when modifying one of the files, all you need to do is restart dropbox and the rest will happen automatically.
Selective sync
If several devices are assigned to our account, we don't always want to have all synced data on all devices. By default, Dropbox works exactly like that, syncing all directories with all devices. If we don't want a directory with photos, we just need to exclude it from syncing, and it will also be removed from that particular computer.
~/drop/dropbox.py exclude add /home/user/Dropbox/Camera\ Uploads/
Excluded:
Dropbox/camera uploads
# display directories excluded from sync:
~/drop/dropbox.py exclude list
Excluded:
Dropbox/camera uploads
Dropbox/winda
Dropbox/android
# restoring synchronization again:
~/drop/dropbox.py exclude remove /home/user/Dropbox/Camera\ Uploads/
One final note: the above text does not apply to individual files!
LAN Sync - synchronization over the local network
If we have several devices with Dropbox installed at home connected to a local network, it's worth using synchronization over the LAN - the transfer will be much faster. On Linux, lansync is enabled by default; from what I remember, it's the opposite on the Windows client.
# enabling lansync:
~/drop/dropbox.py lansync y
# disabling lansync:
~/drop/dropbox.py lansync n
# checking whether lansync is working (LANSync should be displayed from time to time):
watch -n 1 '~/drop/dropbox.py status
# second method
netstat -tunap|grep dropbox
tcp 0 0 192.168.1.6:60420 192.168.1.2:17500 ESTABLISHED 11225/dropbox
tcp 38 0 192.168.1.6:57880 199.47.216.174:443 CLOSE_WAIT 11225/dropbox
tcp 0 0 192.168.1.6:36301 199.47.217.177:443 ESTABLISHED 11225/dropbox
tcp 0 0 192.168.1.6:17500 192.168.1.2:3683 ESTABLISHED 11225/dropbox
If, despite having lansync enabled, we don't see synchronization happening over the LAN, it's possible the firewall is blocking it. Dropbox needs port 17500 TCP/UDP open. If our firewall is based on iptables, we add two rules (this is just an example, you might have different network interface naming, e.g. eth2):
iptables -A INPUT -i eth0 -p tcp --dport 17500 -j ACCEPT
iptables -A INPUT -i eth0 -p udp --dport 17500 -j ACCEPT
As I mentioned earlier, Dropbox by default has the LANsync service running, which involves broadcasting UDP packets every 30 seconds. In a situation where Dropbox is installed on a remote machine (dedicated server, VPS), there's no need to bombard neighbors with UDP packets.
Sharing and collaborating on files
Sharing files is very simple - just copy the file to the special directory /home/user/Dropbox/Public, and then generate a link by issuing the command: ~/drop/dropbox.py puburl ~/Dropbox/Public/file. Sharing files isn't implemented in the dropbox.py script - here you have to use the web interface or graphical clients. More about sharing here: https://www.dropbox.com/help/167.