Created
March 2, 2020 08:41
-
-
Save jay-w-opus/535fe8b4cf60f7fe557e1a6ab0a8924f to your computer and use it in GitHub Desktop.
unison sync tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is for Mac OS X | |
# Your remote Linux server should have unison of the same version (check unison -version). | |
# this file allows you to sync a local folder to a remote server's location via ssh | |
# it supports two modes: | |
# 1. continuous watch-and-sync, if you provide one argument, which is the ssh server's Host name (defined in .ssh/config). | |
# If you need to exit, you need to press ctrl+c twice | |
# 2. one-time batch sync, if you provide multiple ssh hosts. | |
remote_dir=YOUR_REMOTE_FOLDER # target directory path | |
which unison | |
if [[ $? -ne 0 ]] | |
then | |
brew install unison | |
fi | |
pushd $(dirname ${BASH_SOURCE[0]})/.. | |
if [[ $# -eq 1 ]] | |
then | |
echo "Repeat mode" | |
repeat_arg='-repeat watch' | |
fi | |
while true | |
do | |
for host in $@ | |
do | |
unison . ssh://${host}/${remote_dir} -force . -ui text \ | |
-batch ${repeat_arg} -retry 100 -links true -logfile /dev/null \ | |
-ignore "Name {.*,*}.(sw[pon])" -ignore "Name venv" -ignore "Name venv.nosync" \ | |
-ignore "Name db/*.json" -ignore "Name .idea" \ | |
-ignore "Name .DS_Store" -ignore "Name *.db" -ignore "Name *.pyc" -ignore "Name __pycache__" | |
# customize your ignore list above | |
exit_code=$? | |
echo "exit_code=${exit_code}" | |
done | |
if [[ ! -z ${repeat_arg} ]] | |
then | |
echo ${exit_code} | |
if [[ ${exit_code} != 3 ]] | |
then | |
break | |
fi | |
echo 'Wait 5 seconds...Or press ctrl+c again to exit' | |
sleep 5 | |
else | |
break | |
fi | |
done | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment