Getting un-hooked
You Git
I have been using Git Hooks to sync local Hugo website files to my remote server. This has worked well, mostly, but I wondered if it was the most efficient way of syncing up.
I use Git on the local web structure and so have version control. Using Hooks allows me to upload to a remote location and then have the remote server copy the modified file into the live site directory,. This involves a few steps and some repetition and isn’t completely error free. If the Hooks location gets out of sync, which it did for me a couple of times I had no alternative, at least one that worked, but to recreate the Hook directory and start again.
While this isn’t a big issue but one I would rather avoid, if I can, and so I am now trying the old Rsync method.
I don’t know if it is a MacOS issue but rsync on Mac doesn’t seem to work as expected using the online example, for Linux, and so it took me some experimentation to get a command that worked.
Remote Sync or rsync to its friends
Rsync is a fairly simple tool available on most OS’s these days and was originally written in C back in 1996 and is used to synchronise files and local and remote computers. It is also available as a Daemon that runs in the background to keep locations in sync. I am not using that aspect as I only need to run a sync after I edit a post for this website.
The command I use in Hugo, to achieve this from my Mac to a remote Linux server is as follows:
rsync -uavP --delete public/ user@example.com:<PATH TO>/html/website/
The options are explained in the Man page and the –delete option deletes files on the remote that aren’t on the local machine. This can be dangerous so it may be worth running --dry-run
first -n
is the short form.
The -uavP
options are the ones that I had to figure out as the often proffered linux ones didn’t seem to work for me, no idea why. But it isn’t important now as these work for me.
In closing this is a fairly easy way of uploading to a server, and once I got the options figured out it seems to work quickly, the capital -P
flag, “Partial & Progress”, shows progress and it is nice to see the files fly away.