Skip to content

Instantly share code, notes, and snippets.

@xaptronic
Created October 28, 2011 00:13
Show Gist options
  • Save xaptronic/1321266 to your computer and use it in GitHub Desktop.
Save xaptronic/1321266 to your computer and use it in GitHub Desktop.
File System Sync will copy changes to files to a remote machine.
remote=$1
default_remote=$remote
rsync_extra=$2
if [ -z "$remote" ]; then
echo "Usage: fs_sync <sync_to>"
echo "Syncs changes made to the current directory tree to <sync_to>"
echo "E.g.; alex@hactar ~/dev/trunk $ fs_sync tpweb:code/trunk"
echo "Files in the current directory tree (~/dev/trunk) will be automatically pushed to tpweb:code/trunk whenever a change is made."
echo "Additionally you may define environment variables in the form git_sync_[branchname]=tpweb:code/other to push particular branches to specific remote locations and rely on the passed in remote as the default location."
exit 1;
fi
fs_root=`pwd`
while inotifywait -q -q -r -e modify $fs_root;
do
echo "syncing changes..." `date +%k:%M:%S.%N`;
# If we are in a git repo then figure out what branch and where to sync that branch
git status -s &> /dev/null
if [ $? -eq 0 ];
then
source ~/.git_sync
git_branch=`git branch | grep ^* | awk '{ print "git_sync_"$2 }'`
echo $git_branch
if [ "${!git_branch}x" != "x" ];
then
remote=${!git_branch}
else
remote=$default_remote
fi
fi
echo "sync to " $remote
#rsync -rlzCc $rsync_extra \
rsync -az $rsync_extra \
--exclude=*~ \
--exclude=*.swp \
$fs_root/* $remote;
echo "completed..." `date +%k:%M:%S.%N`;
done
remote=$1
rsync_extra=$2
if [ -z "$remote" ]; then
echo "Usage: sf_sync <sync_to> (what environment)"
echo "Syncs changes made to the current directory tree to <sync_to>"
echo "E.g.; alex@hactar ~/dev/trunk $ sf_sync local"
echo "Files in the current directory tree (~/dev/trunk) will be automatically pushed to tpweb:code/trunk whenever a change is made."
exit 1;
fi
sf_root=`pwd`
[ ! -e $sf_root/symfony ] && echo "Make sure you run this in a symfony 1.x root dir" && exit;
while inotifywait -q -q -r -e modify $sf_root;
do
echo "syncing changes..." `date +%k:%M:%S.%N`;
rsync -rlzCc --force --delete $rsync_extra \
--exclude-from=$sf_root/config/rsync_exclude.txt \
$sf_root/* $remote;
echo "completed..." `date +%k:%M:%S.%N`;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment