Code Monkey home page Code Monkey logo

bitpocket's Introduction

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/sickill/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/sickill/bitpocket/master/bin/bitpocket > ~/bin/bitpocket
$ chmod +x ~/bin/bitpocket

Setting up master

Create 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 empty directory as your bitpocket:

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

Manual sync

Now whenever you want to sync with master just run bitpocket sync inside your bitpocket directory:

$ cd ~/BitPocket
$ bitpocket sync

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.

Configuration

Exclude files

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.

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`'

Displaying logs

When running bitpocket in cron with bitpocket cron it will append its output to .bitpocket/log file. You can watch live log with following command:

$ cd ~/BitPocket
$ bitpocket log

Author

Marcin Kulik | @sickill | https://github.com/sickill | http://ku1ik.com/

bitpocket's People

Contributors

ku1ik avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.