March 21, 2014

Sync local files and folder to remote

Working in a team project which uses VPN as a virual host where you will see your own changes or can be viewed by team members, however everytime someone made a change and you need to pull from GIT or other Version Control tools, you need to send these changes to the remote server, here is how I automated my process, or at least reduce the process, I am using sublime as my IDE, most people recommend PHP Storm for our project, however I just like to stay with sublime for their lightweight and packages, I installed SFTP for sublime which comes with a trial of 30 days, or you can pay after that for $20 bucks, SFTP allow me to sync local files and folder to remote or remote to local, or two ways sync.

There is a settings that I love alot is the

[cc lang="php"]"upload_on_save": true

Once you click save, the file will be automatically send to remote, and there are so much settings you can do with SFTP sublime.

Just check official Usage page.

However!!! It does not watch my folder, when I do a Git pull, there are so much files downloaded and files changes, the bad thing is SFTP does not watch that for me and upload these changes to remote.

So here comes with alternative solution for this problem, most Mac comes with Rsync, if you are not sure, just type rsync on your terminal.

rsync allows to sync files and folder from one location to another, the best is support remote server SSH access, since it use SSH, you do not even need to login with your password every time you do a sync.

First Upload your rsa keys to SSH, make sure you can access without password

if you do not have ras, do this
[cc lang="php"]ssh-keygen -t rsa

Now you can start to sync your files from local to remote by using rsync command

rsync -av folder_name/

r – Recursive

l – Transfer any symlinks encountered

t – Preserve time stamps

p – Preserve permissions

g – Preserve groups

o – Preserve ownership

D – Preserve block and character devices

h – Human-readable format of file size

its just as easy as that, its very fast, and it watch the files that changed and sync from local to remote