• Stars
    star
    1,023
  • Rank 43,285 (Top 0.9 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 13 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

"DIY Dropbox" or "2-way directory (r)sync with proper deletion"

bitpocket

About

bitpocket is a small but smart script that does 2-way directory synchronization. It uses rsync to do efficient data transfer and tracks local file creation/removal to avoid known rsync problem when doing 2-way syncing with deletion.

bitpocket can use any server which you have ssh access to for its central storage. If you have gigabytes of free disk space on your hosting server you can finally make use of it.

Installation

Clone repository and symlink bitpocket bin to sth in your $PATH:

$ git clone git://github.com/ku1ik/bitpocket.git
$ ln -s `pwd`/bitpocket/bin/bitpocket ~/bin/bitpocket

Or download script and place it in a directory in your $PATH:

$ curl -sL https://raw.github.com/ku1ik/bitpocket/master/bin/bitpocket > ~/bin/bitpocket
$ chmod +x ~/bin/bitpocket

Setting up master

Create an empty directory on some host that will be the master copy of your files:

$ ssh [email protected]
$ mkdir ~/BitPocketMaster

Setting up slaves

On each machine you want to synchronize initialize an empty directory as your bitpocket:

$ mkdir ~/BitPocket
$ cd ~/BitPocket
$ bitpocket init [email protected] ~/BitPocketMaster

Usage

After installation, you use the bitpocket command for synchronization and other tasks. Running bitpocket help will display the following message.

usage:  bitpocket { init [<REMOTE_HOST>] <REMOTE_PATH>
                  | sync | help | pack | log | cron | list }

Available commands:
   sync    Run the sync process. If no command is specified, sync is run by
           default.
   init    Initialize a new bitpocket folder. Requires path and optional
           remote host params. Remote path must already exist.
   pack    Pack any existing (automatic) backups into a git repository.
   cron    Run sync optimized for cron, logging output to file instead of
           stdout.
   log     Display the log generated by the cron command
   list    List all files in the sync set (honoring include/exclude/filter
           config).
   help    Show this message.

Options:
   -f, --force      Clean up stale lock files automatically
   -p, --pretend    Don't really perform the sync or update the current
                    state. Instead, show what would be synchronized.

Note: All commands (apart from help), must be run in the root of a
      new or existing bitpocket directory structure.

Manual sync (bitpocket sync)

To synchronize your local slave with master just run bitpocket sync inside your bitpocket directory:

$ cd ~/BitPocket
$ bitpocket sync

Ensure that you run bitpocket at least once immediately after creating a new slave and before adding new files to the slave directory. If there are files in the master they will be pulled into the slave. You may then move files into your slave directory and they will be detected as added.

Maintaining backups (bitpocket pack)

bitpocket does not include a full-fledged versioning system at the moment, but it does automatically create a local backup of any files before overwriting or deleting with changes from the BitPocketMaster. These backups are placed into a timestamped directory (one directory per sync). The path to this directory is:

.bitpocket/backups/YYYY-MM-DD.hhmmss

As these files accumulate, you may want to remove them, but you can also run bitpocket pack to combine all the backup files into a git repository contained within the .bitpocket directory:

$ cd ~/BitPocket
$ bitpocket pack

This requires an installation of git, but allows all the space saving advantages of git when making repeated changes to the same files.

There is a discussion about potential directions for versioning direction here: github.com/ku1ik/bitpocket/issues/15

Redirecting output to log file (bitpocket cron)

If bitpocket is run with the cron parameter ( bitpocket cron ), it will perform a sync, but instead of showing the progress on stdout, it will redirect all output to a log file:

$ cd ~/BitPocket
$ bitpocket cron

As the name of this parameter implies, this is mainly useful when running bitpocket through the cron command. (See "Automatic sync with cron" for more information about how to configure this).

Displaying logs (bitpocket log)

When running bitpocket in cron with bitpocket cron it will append its output to .bitpocket/log file. You can review the tail end of an existing log file, or watch live log as it is generated, with following command:

$ cd ~/BitPocket
$ bitpocket log

Displaying list of files to be synchronized (bitpocket list)

You may want to know which files will be synchronized before actually performing the syncronization. You can verify which files are in the synchronization set by running bitpocket list:

$ cd ~/BitPocket
$ bitpocket list

Note that this does not list changed files, it only lists all the local files that bitpocket will look at in determining which files to sync. Also, note that if there are new files in the master that will be added on a sync, they will not be included here. This command is only intended to verify which files are in the synchronization set. (See "Configuring file exclusion and inclusion" for information about how to control which files are in the synchronization set).

Configuration

Automatic sync with cron

Add following line to your crontab to synchronize every 5 minutes:

*/5 * * * * cd ~/BitPocket && nice ~/bin/bitpocket cron

Note that cron usually has very limited environment and your ssh keys with passphrases won't work in cron jobs as ssh-agents/keyrings don't work there. Thus it's preferable to generate passphrase-less ssh key for bitpocket authentication:

$ cd ~/BitPocket
$ ssh-keygen -t rsa -C bitpocket-`hostname` -N '' -f .bitpocket/id_rsa
$ ssh-copy-id -i .bitpocket/id_rsa [email protected]

and uncomment line with RSYNC_SSH in .bitpocket/config file.

Configuring file exclusion and inclusion

If you want some files to be ignored by bitpocket you can create .bitpocket/exclude file and list the paths there:

*.avi
jola
/misio.txt

*.avi and jola will be matched anywhere in path, misio.txt will be matched at bitpocket root dir ( ~/BitPocket/misio.txt ).

This exclude file is passed to rsync as --exclude-from argument, check man rsync for INCLUDE/EXCLUDE PATTERN RULES.

You can set up even more advanced exclusion/inclusion rules. In all, there there are three files that you can create to change this configuration:

.bitpocket/exclude
.bitpocket/include
.bitpocket/filter

Be aware that all the quirks from rsync exclusion/inclusion rules carry over into bitpocket. If you decide that you need such advanced configuration, make sure that you understand those rules very well, and consider double checking them before syncing by running bitpocket list.

Backup options

Both local and remote backups can be enabled or disabled in the configuration. By default, local backups are enabled and remote backups are not. Based on how intend to use bitpocket, you may wish to change this behavior. Add or change these lines in your .bitpocket/config file:

# BACKUPS=true
# REMOTE_BACKUPS=false

Custom rsync options

You can pass additional switches to rsync by setting RSYNC_OPTS in .bitpocket/config file. Generated config file includes (commented out) example setting for dereferencing symlinks:

# RSYNC_OPTS="-L"

Just uncomment it and change at will.

Slow sync callbacks

When syncing takes more than 10 seconds (SLOW_SYNC_TIME setting) bitpocket can fire off user provided command in background. This can be usefull to notify user about long sync happening, preventing him from turning off the machine during sync etc.

There are 3 settings that can be enabled in .bitpocket/config file:

# SLOW_SYNC_TIME=10
# SLOW_SYNC_START_CMD="notify-send 'BitPocket sync in progress...'"
# SLOW_SYNC_STOP_CMD="notify-send 'BitPocket sync finished'"

Just uncomment them and change at will.

You can show tray icon during long sync with traytor and following settings:

SLOW_SYNC_START_CMD='~/bin/traytor -t "BitPocket syncing..." -c "xdg-open ." .bitpocket/icons & echo $! >.bitpocket/traytor.pid'
SLOW_SYNC_STOP_CMD='kill `cat .bitpocket/traytor.pid`'

Failsafes

You can add a remote mount point check to ensure a remote path is available prior to the sync running. If the folder is not mounted on the remote server, then the sync will be aborted. The path must be an absolute path which is expected to be a mountpoint on the remote server. Add or change this lines in your .bitpocket/config file:

# REMOTE_MOUNTPOINT=/

Author

More Repositories

1

vim-monokai

Monokai color scheme for Vim converted from Textmate theme
Vim Script
1,420
star
2

stderred

stderr in red
C
973
star
3

git-dude

Git commit notifier
Shell
949
star
4

rainbow

Ruby gem for colorizing printed text on ANSI terminals
Ruby
792
star
5

racksh

Console for Rack based ruby web apps
Ruby
423
star
6

vim-pasta

Pasting in Vim with indentation adjusted to destination context
Vim Script
321
star
7

coloration

Textmate to Vim, JEdit and Kate/KWrite color scheme converter
Ruby
257
star
8

css2less

Css to LessCss converter
Ruby
62
star
9

off-plugin

Plugin for Netbeans and JEdit for quick finding and opening files by typing just few characters
Java
44
star
10

vim-sunburst

Sunburst color scheme for Vim converted with coloration.ku1ik.com from Textmate theme with the same name.
Vim Script
27
star
11

dotfiles

My virtual home
Vim Script
27
star
12

rack-revision-info

Rack middleware showing current git (or svn) revision number of deployed application
Ruby
20
star
13

rack-lesscss

Rack middleware for serving LessCSS files compiled to CSS
Ruby
14
star
14

tm2jed

Texmate-To-JEdit colour theme converter - NOTE: DEVELOPMENT MOVED TO sickill/coloration repo
Ruby
9
star
15

kanbanery-ruby-client

Ruby client library and CLI for Kanbanery.com
Ruby
8
star
16

ps

Unix "ps" on the web.
Ruby
7
star
17

traytor

Show (animated) tray icon from command line
Python
7
star
18

example-rack-framework

Example ruby web framework built with Rack
Ruby
6
star
19

skype-kde-notifications

Displaying Skype incoming messages with KDE4 visual notifications
Python
6
star
20

homepage

Personal homepage / blog
CSS
5
star
21

coloration-web

Web frontend for Coloration
CSS
5
star
22

merb-resque-mailer

Merb plugin for putting mail delivery jobs onto Resque queue
Ruby
4
star
23

krug-merb-presentation

Ruby
4
star
24

rubytime-plasmoid

Rubytime plasmoid with support for adding activities and notifications
C
4
star
25

vim-git-inline-diff

Git inline diff for Vim using Vim's signs feature
Vim Script
4
star
26

vimbanery

Vim-like keybindings for Kanbanery
JavaScript
4
star
27

canvator

HTML5 Canvas element demo
C++
4
star
28

gratifier

Desktop notifications with Gravatars!
Shell
3
star
29

archlinux-nginx-passenger

Nginx webserver with Passenger module for Archlinux
Shell
3
star
30

blogator

My old homepage/blog created with Sinatra + Datamapper
JavaScript
3
star
31

krug-chef-presentation

JavaScript
3
star
32

sickounter

Simple Sinatra powered downloads counter
Ruby
3
star
33

euruko2010-building-frameworks-with-rack

My Euruko 2010 conference presentation about building ruby web frameworks using Rack and available middleware
JavaScript
3
star
34

yeb

Ruby
3
star
35

kodr

Programmer's editor for KDE4 written in Ruby
Shell
3
star
36

expo

Beautiful html photo album generator
Ruby
2
star
37

minion

Dead simple ruby background jobs without workers
Ruby
2
star
38

clj-bwt

Clojure implementation of Burrows-Wheeler transform (block-sorting compression)
Clojure
2
star
39

ts-hermit

JavaScript
2
star
40

openfilefast-headless

Tool to find a file in a project (dir) using fuzzy matching (this is backend only, to be used with gui frontend)
Ruby
2
star
41

ecto-preload-bug

Example project for demonstrating Ecto preload bug
Elixir
2
star
42

tsm

Ruby
2
star
43

tmux

C
2
star
44

mail_friday

Ruby
2
star
45

urack

rack + usher + warden + tilt + rack-flash + ...
Ruby
2
star
46

flash

Keep the secrets out of emails and chat history!
Elixir
2
star
47

luna

Fresh Rails app for "Setting up fresh Ubuntu server for Rails" LLP workshop
Ruby
2
star
48

omnomnom

sinatra+heroku test app
Ruby
2
star
49

finish-him

Word autocomplete (expansion) plugin for JEdit editor written in Scala
Scala
2
star
50

gts-move-on

Clojure
1
star
51

phoenix-1.3-to-dev

Elixir
1
star
52

bitflip-gen

Rust
1
star
53

bb-lb-400

1
star
54

brunch-issue

CSS
1
star
55

tarpit

Tarpit for ssh/smtp/http
Rust
1
star
56

collatz-conjecture-rs

Collatz conjecture solver
Rust
1
star
57

nemesis

1
star
58

chrome-browserid

JavaScript
1
star
59

gh-356

JavaScript
1
star