Tullio Facchinetti

Using rsync to update a remote Hugo website

by Tullio Facchinetti

Categories: article lang_en article_en


After having moved to Hugo for my personal website, I found that the usual way of using rsync to update the copy of the website on the remote server does not work efficiently. In particular, everytime I rebuild the local copy of the site with Hugo, and I run the command to synchronize the remote copy, all the local files are uploaded to the server.

This happens because Hugo regenerates all the files at every local build. For this reason, when rsync checks the changes in the modification times between local and remote files, the local ones are all always newer, and thus all of them are uploaded remotely.

To limit this problem, I use this workaround. I have a local directory called upload/, which is located in the same Hugo base directory. The upload/ directory is kept synchronized with the Hugo’s public/ directory. The synchronization is not done by modification date, but by file checksum, which is one of the methods provided by rsync. In this way, the files in the upload/ directory are updated only when there is an actual change in the content within the public/ directory.

Afterwards, I can use the usual remote synchronization method between the local upload/ directory and the remote server using the modification times.

The following sync.sh bash script does all the work:

#!/bin/bash

BASEPATH=/your-path-to-local-hugo-base-directory/

rsync -r --delete --checksum $BASEPATH/public/ $BASEPATH/upload/
rsync -avz --delete $BASEPATH/upload/ username@your-server:remote-directory/

It would be possible to directly perform the synchronization between the local public/ directory and the remote server using the checksum method. However, this incurs in a large overhead due to the checksum operations done in the remote machine.


Highlights

  • Students and theses
  • Publications
  • Thesis topics
  • Curated awesome list of CLI apps
  • Last updates (English)

  • Students and theses ()
  • Students and theses - English ()
  • Learn enough C to survive ()
  • Workflow for writing theses collaboratively ()
  • Guidelines for theses and presentations ()
  • Projects ()
  • Shortcuts for Bash ()
  • Last updates (Italian)

  • Risultati FdI 03 Febbraio 2023 ()
  • Risultati FdI 21-25 Novembre 2022 ()
  • Studenti e tesi ()
  • Risultati FdI 29 Settembre 2022 ()
  • Risultati FdI 02 Settembre 2022 ()
  • Risultati FdI 28 Luglio 2022 ()
  • Risultati FdI 29 Giugno 2022 ()
  • List of categories

    article article_en article_it C courses fdi lang_en lang_it latex programming project research results robotics software teaching thesis tips