After some time of writing blog with Hugo. It becomes clear to me that updating my hosting to reflect the newest article is a very painful process. So painful in fact, that I decided to just upgrade my hosting to allow SSH access. With SSH access, we can use Rsync!
What is Rsync
It is just a tool that can help you synchronize two directories. Fortunately, the directories can be on 2 different computers. Rsync achieves this “magically” through SSH. So if you hosting allows SSH. Simply use rynsc with the following command template.
rsync -avP <local folder>/ user@host:<remote folder>
Notice that the local folder ends with / so it won’t create a subfolder in your target. So if you use Hugo,
simply run this:
rsync -avP public/ user1@192.168.1.1:/home/user/public_html/hugo.softwarejourney.site
Non-Standard SSH port
Hosting likes to use non-standard SSH port. To support it, we must pass -e 'ssh -p <port numnber>' as additional
option, preferably after -avP switch, like so:
rsync -avP -e 'ssh -p 65002' public/ user1@192.168.1.1:/home/user/public_html/hugo.softwarejourney.site
Notes
One notable of using Rsync over version control is we can easily correct mistake. Before publishing this article, I actually made a mistake by providing too much information in the example commands. Because they are just files, it’s simply overidden and the mistake is no more. If use version control, we have to manipulate the history tree.
References
Shoutout to this digital ocean article for helping me learn about rsync
Programming