O'Reilly logo

Go Programming Blueprints - Second Edition by Mat Ryer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The daemon backup tool

The backup tool, which we will call backupd, will be responsible for periodically checking the paths listed in the filedb database, hashing the folders to see whether anything has changed, and using the backup package to actually perform the archiving of the folders that need it.

Create a new folder called backupd alongside the backup/cmds/backup folder, and let's jump right into handling the fatal errors and flags:

func main() { var fatalErr error defer func() { if fatalErr != nil { log.Fatalln(fatalErr) } }() var ( interval = flag.Duration("interval", 10 * time.Second, "interval between checks") archive = flag.String("archive", "archive", "path to archive location") dbpath = flag.String("db", "./db", "path to filedb database") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required