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

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

  • Students and theses ()
  • Students and theses - English ()
  • Speed up the compilation of LaTex Beamer presentations ()
  • Learn enough C to survive ()
  • Workflow for writing theses collaboratively ()
  • Guidelines for theses and presentations ()
  • Projects ()
  • Last updates (Italian)

  • Risultati FdI 18 Novembre / 02 Dicembre 2024 ()
  • Studenti e tesi ()
  • Risultati FdI 27 Settembre 2024 ()
  • Risultati FdI 02 Settembre 2024 ()
  • Risultati FdI 25 Luglio 2024 ()
  • Risultati FdI 26 June 2024 ()
  • Risultati FdI 8 e 11 aprile 2024 ()
  • 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