Hync - Home direcory synchronization via SSH
Hync is a python script that uses rsync in combination with ssh to securely synchronize linux user home directories on different hosts. Also no special server or service provider is used. So you can just synchronize your devices in your home network with all the preferences of your programs.
Features
- secure synchronization via ssh
- running in background and syncing if the other host is reachable
- synchronisation points are highly configurable through configuration files
- hosts can be identified by multiple addresses with priority (e.g. for notebooks which change their location, local network or internet)
- ssh and rsync commands can be modified
- exclude files or directories (e.g. '.cache')
- does not synchronize with hosts where hync is active
Requirements
- python >= 3.0.0
- running ssh-server
- ssh-client
- configured ssh-keys for login without password (e.g. described here)
- rsync
- synchronized clocks
Download
How does it work?
When hync is started, it will try to connect to the hosts defined in the configuration file. Then hync compares the last activity of hync with those of the remote hync directory. Based on this hync pulls or pushes the changes via rsync from/to the remote host and refreshes the last activity timestamp. The pull operation is only executed if hync just started. After the first round of synchronizations hync determines the current host as active and will not pull anything to avoid inconsistent program-data. Also other hync processes on remote hosts will not push anything to the active host for the same reason. In active state hync updates the timestamp to the current time.
The behaviour of hync can be modified through command options:
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-i, --non-interactive
Disable Interactive mode
-v, --verbose Verbose output-mode
-d, --daemon Run as daemon-process
-s, --disable_push Disable pushing changes
-l, --disable_pull Disable pulling changes
-r, --reset Reset the time on this profile
-m, --daemonize-im Disable first-run observation, daemonize immediately
-w, --writeback On Program stop, force a writeback of data
-o, --onerun Start the program only for one run
-c CONFIG_FILE, --config=CONFIG_FILE
Configuration file
-n INTERVAL, --interval=INTERVAL
Check interval for synchronization (default: 300)
-p, --no-push-first Disable pushing changes in the first round
-L, --license License information
Configuration
Notice: Setting the excludes in the configuration file will overwrite the normal exclude ('.hync/run,.ssh'). Especially the first one is necessary if you are synchronizing your home directory. But to give the user all possibilities, I decided not to hardcode those two excludes.
To configure hync you have to create a directory in your home '~/.hync/config/'. This directory contains all configs from all hosts that are synchronized. The config file name is the hostname. Through this you can define different behaviour for every host.
Here is the sample-configuration from above:
# This configuration file has to be placed in ~/.hync/config/<HOSTNAME>
# where <HOSTNAME> has to be replaced by that of the host using this config.
# In the following every sync consists of several locations. Every location
# consists of one or more host entries.
# general options to provide information about this system.
[general]
# the location this host represents. Through this entry you can use
# the rest of the config without changes.
local_locations = aplus
# host entries specify the real address of a host, the user, special ssh and
# rsync options to use.
[host_dockstar]
addr = 192.168.0.5
user = scosu
ssh = -i /local/.ssh/lsync
[host_aplus]
addr = 192.168.0.13
user = scosu
# A location represents a path in the filesystem of a host.
# Due to the existence of configurations, where one location
# is reachable through different addresses, you can specify
# more than one host in the 'hosts' field seperated by commas.
# The hosts are processed every round beginning with the first host.
# As long as no reachable host is found, the next host is processed.
# An example for this is a notebook which connects sometimes via the
# internet IP and sometimes via the local IP.
[loc_dockstar]
hosts = dockstar
user = scosu
path = /home/scosu/remote_home/
[loc_aplus]
hosts = aplus
user = scosu
path = /home/scosu/
# Finally we set up a synchronization point. Specify all locations
# should be synchronized. Also you can add some excludes (only relative paths)
# seperated by commas.
[sync_home]
locations = dockstar, aplus
exclude = .cache/
The identifiers in '[]' have as prefix the type of section (loc_ = location, sync_ = synchronization point, host_ = host). There are additional settings; rsync_host (rsync options in the host section) and rsync_syn (in the sync section). Be careful with the last one. It overwrites the normal options for rsync ('-aSv --delete').
License
hync is a small program to synchronize user home directories without
a special server.
Copyright (C) 2010 Markus Pargmann (mpargman <AT> allfex.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.