Skip to content

Instantly share code, notes, and snippets.

@mfellner
Created June 9, 2013 15:42
Show Gist options
  • Save mfellner/5743990 to your computer and use it in GitHub Desktop.
Save mfellner/5743990 to your computer and use it in GitHub Desktop.
Sync a local and a remote directory with rsync over sshfs (e.g. when you only have sftp access). Note the defer_permissions option and the -c (checksum) flag. Tested on OS X with rsync 2.6.9 and sshfs 2.4.0 (fuse4x 0.9.2).
#!/bin/bash
SSH_USER="[email protected]" # your sftp credentials
SSH_KEY="~/.ssh/id_rsa" # your ssh private key
DOCUMENT_ROOT="/www/vhosts/mywebsite.com/htdocs" # directory on the remote server
LOCAL_DIR="~/mywebsite.com/public" # directory on your local machine
REMOTE_DIR="_remote_dir" # temporary mount point
mkdir -p $REMOTE_DIR
sshfs $SSH_USER:$DOCUMENT_ROOT $REMOTE_DIR -o workaround=rename -o defer_permissions -o IdentityFile=$SSH_KEY
rsync -rlvcP --delete $LOCAL_DIR $REMOTE_DIR
umount $REMOTE_DIR
rm -r $REMOTE_DIR
@bitwombat
Copy link

These options will make things really slow, since rsync will have to first read the entire file over sshfs (to get a checksum).
I'm using these:

rsync -rv --size-only --no-group --no-owner --no-perms --no-times --whole-file --inplace

--whole-file prevents it having to read the file in order to figure out what the difference is.
--inplace prevents a bunch of lstats and renames

@axelsegebrecht
Copy link

works find when I take out the create/remove temporary mount points

(on ubuntu 16 LTS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment