Skip to content

Instantly share code, notes, and snippets.

@msanders
Last active January 13, 2024 18:02
Show Gist options
  • Save msanders/1f855af3ec4e6ef5ed12b64d447bd148 to your computer and use it in GitHub Desktop.
Save msanders/1f855af3ec4e6ef5ed12b64d447bd148 to your computer and use it in GitHub Desktop.
Automatically backup Kobo eReader with Hammerspoon

Example config to automatically backup Kobo eReader to ~/Backups/Kobo/ whenever it is mounted using rsync. Can be copied to Hammerspoon init.lua config file.

Tested on Hammerspoon 0.9.100, macOS 14.2.

local log = hs.logger.new("kobobackup")
local koboMountPath = "/Volumes/KOBOeReader"
local koboBackupDirectory = os.getenv("HOME") .. "/Backups/Kobo/"
local pendingTask = nil
local restartBackup = false
local function backupKobo()
if hs.fs.volume.allVolumes()[koboMountPath] == nil then
log.i("Kobo volume unmounted; skipping backup")
elseif pendingTask == nil then
local startTime = hs.timer.absoluteTime()
pendingTask = hs.task.new("/usr/bin/rsync", function()
pendingTask = nil
if restartBackup then
log.i("Kobo backup restarting...")
restartBackup = false
backupKobo()
else
local endTime = hs.timer.absoluteTime()
local diffMs = (endTime - startTime) / 1000000
hs.alert.show("Backed up Kobo")
log.f("Kobo backup finished in %.fms", diffMs)
end
end, {
"--archive",
"--update",
"--delete",
"--exclude",
".Trashes",
"--exclude",
".Spotlight-V100",
koboMountPath,
koboBackupDirectory,
}):start()
log.i("Kobo backup started")
else
restartBackup = true
log.i("Kobo backup invalidated due to file system change")
end
end
koboPathwatcher = hs.pathwatcher.new(koboMountPath, backupKobo):start()
backupKobo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment