Whenever I write something about synchronization, I am required, by law, to reference this picture:
If you don’t get it, just let it slide.
Disclaimer: Vim/emacs users, stop reading. Now. Probably.
As with all useful articles, we are ultimately aiming to solve a problem. The problem we would like to amend is the slow process of developing projects on a remote sever.
Hence, what we are trying to achieve is Simple, iterative process of developing projects on a remote server
After launching a Amazon EC2 Ubuntu instance, I moved all my projects to the server in order to run them, and they instantly broke. Thankfully, I had setup a logging mechanism, so I realized what the problems were, but now I need to fix them!
I launch my favorite IDE, PyCharm, and fix those issues, and commit to the VCS. Only problem now is, I need the server to get those changes!
First thing I did was, I would ssh into the server, navigate to the project root, and pull latest, execute a deploy script. This deemed very mundane and time consuming!
I then tried utilizing an old script I had, which uses
scp, to transfer my files. The problem now was, scp was transferring everything, every single time. Not only that, but I no longer need the
.git directory to be sent, as well as all the patterns that are specified in the
.gitignore! Something had to change. It was time to learn something new.
After searching on how to exclude files from
scp, the answer was: “You can’t. Use rsync, instead”. Best part about this is,
rsync comes with so many more benefits other than excluding files, as we we’ll see now.
rsync’s beauty in this context can be described in three points:
- Effeciency: Only sends the new/changed files! Doesn’t transfer the whole directory every single time, like scp did.
- Control: Using
--include, --exclude, you can easily control what gets synced, and what doesn’t.
- Organization: By specifying the
--deleteoptions, files deleted locally will also be deleted from the remote directory.
Needless to say, that’s all I ever wanted.
Now, let’s take a look at how this works:
With all that setup in the pythonic terminal, it’s as tasty as pie!