Skip to content

Instantly share code, notes, and snippets.

@shegeley
Created February 16, 2026 02:34
Show Gist options
  • Select an option

  • Save shegeley/8c518c5c4082a053db6a42d1a1978264 to your computer and use it in GitHub Desktop.

Select an option

Save shegeley/8c518c5c4082a053db6a42d1a1978264 to your computer and use it in GitHub Desktop.
Borgmatic Guix Sample Job
(use-modules
(srfi srfi-1)
(guix gexp)
(gnu services)
(gnu services shepherd)
((gnu packages ssh) #:select (openssh))
((gnu packages backup) #:select (borgmatic)))
(define (borgmatic-backup-cmd config-file)
#~(list (string-append #$borgmatic "/bin/borgmatic")
"--verbosity" "2"
"--config" #$config-file))
;; see (@@ (gnu services backup) restic-backup-job->shepherd-service)
(define* (borgmatic-job
#:key
job-name
config-file
user
group
(log-file (string-append
"/var/log/borgmatic/"
(symbol->string job-name) ".log"))
;; (at 02:00 [AM])
(scheduling #~(calendar-event #:hours '(2) #:minutes '(0))))
(let [(envs #~(list
(string-append "TMPDIR=/tmp")
(string-append "PATH=" #$openssh "/bin")
(string-append "HOME=" (passwd:dir (getpwnam #$user)))))]
(shepherd-service
(provision (list (symbol-append 'borgmatic '/ job-name)))
(requirement '(user-processes
file-systems
ssh
networking))
(modules '((shepherd service timer)))
(start #~(make-timer-constructor
#$scheduling
(command
#$(borgmatic-backup-cmd config-file)
#:user #$user
#:group #$group
#:environment-variables #$envs)
#:log-file #$log-file
#:wait-for-termination? #t))
(stop #~(make-timer-destructor))
(documentation "Borgmatic backups")
(actions (list (shepherd-action
(inherit shepherd-trigger-action)
(documentation "Manually trigger a backup,
without waiting for the scheduled time.")))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment