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.
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() |