Setting up permissions for bittorrent sync

The goal is to sync a common directory structure over multiple sites.

Permissions on server

  • create sync user:
useradd -g office -d /home/common -c "btsync service" -m btsync
  • Don’t use a sticky bit, or sync will not be able to delete files
  • Make sure all contributors to /home/common have primary group office and umask=002
    • This will mean that they all have read/write access to the common files
  • Recommended to use the SGID bit to lock all new files with group office and prevent this changing
chgrp -R office /home/common
chmod g+s /home/common #just to top directory (assume no sub-directories)
chmod -R g+w /home/common
  • Note that if a user creates a new file, when btsync replicates it on other systems it will lose ownership information (and be owned by btsync). But because it will have group office it will be editable.

First time setup

mkdir -p /opt/bin #the place to put binaries that are not packaged-managed
echo 'su btsync -c "umask 002; /opt/bin/btsync"' > /opt/bin/btsync.sh #run as user btsync. Must force umask here.
# optionally append to the command: --config /etc/btsync.conf
chmod 777 /opt/bin/btsync.sh
ln -sfn /opt/bin/btsync.sh /usr/local/bin/btsync
ln -sfn /opt/bin/btsync.sh /etc/init.d/btsync
runlevel #find runlevel
ln -sfn /etc/init.d/btsync /etc/rc3.d/S65btsync #for runlevel 3

Install/upgrade binary

su #if running on a server, else run as the user who will have access to synced files
glibc=glibc23_ #for CentOS 5 or 6
arch=x64 # or i386
version=1.4.111
binary=$version/btsync_$glibc$arch-$version
pkill btsync      #stop process if this is an upgrade
sleep 3
wget http://syncapp.bittorrent.com/$binary.tar.gz
tar -zxf btsync* -C /opt/bin btsync
rm -f btsync*
chmod 777 /opt/bin/btsync
/etc/init.d/btsync && ps -ef | grep btsync # make sure it is running under correct user

Setup directories to sync

  • Go to client and set up a tunnel:
  • If you want to add new directories, you can only have one server open in a browser at a time or the “add folder” window hangs. (JavaScript issue)
    • You can get arround this by using two different browsers.
ssh root@server -L 8889:localhost:8888 -N
browse: http://127.0.0.1:8889/gui
  • set up sync directores

Launching with systemd

  • bbs.archlinux.org/…ewtopic.php good discussion
  • Create file /etc/systemd/system/btsync.service substituting username
  • You might want to add the —config option
[Unit]
Description=btsync running as myusername
After=network.target

[Service]
Type=simple
User=myusername
ExecStart=/usr/bin/btsync --nodaemon

[Install]
WantedBy=multi-user.target
  • To make it start on boot, use systemctl enable btsync.service

Notes

  • Symlinks are synced as links, not as the contents of the link
  • Use .SyncIgnore but be very careful with it:
    • If new files are added at the other end that are excluded by .SyncIgnore, they will be synced back, but this is one way only.
    • The files can be deleted locally, but as soon as they are changed remotely, they will appear again.
    • The solution is to have an identical .SyncIgnore at every server

Config File

/opt/bin/btsync --dump-sample-config > /etc/btsync.conf #create 
  • Modify device_name
  • comment out login & password
  • optionally under “use_sync_trash” : true, add: “sync_trash_ttl”: 2, # for 2 days trash

Resources: