Added backup machinery
This commit is contained in:
29
main.go
29
main.go
@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"qurl/pages"
|
||||
"qurl/storage"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
//go:generate bindata -m Assets -r assets -p static -o static/assets.go assets
|
||||
@ -17,18 +16,10 @@ func main() {
|
||||
dburl := flag.String("u", "bolt:./qurl.db", "url to database")
|
||||
lsaddr := flag.String("l", "127.0.0.1:8080", "listen address/port")
|
||||
jsonfile := flag.String("j", "", "path to json to load into database")
|
||||
maxpro := flag.Int("m", runtime.NumCPU()+2,
|
||||
"maximum number of threads to use")
|
||||
backupint := flag.Int("i", 86400, "seconds between database backups")
|
||||
backupdir := flag.String("b", "", "destination directory for database backups")
|
||||
flag.Parse()
|
||||
|
||||
if *maxpro < 3 {
|
||||
fmt.Fprintf(os.Stderr, "Thread limit too low: %d (min 3)\n", *maxpro)
|
||||
return
|
||||
}
|
||||
|
||||
// Limit max processes
|
||||
runtime.GOMAXPROCS(*maxpro)
|
||||
|
||||
// Open storage backend
|
||||
stor, err := storage.NewStorage(*dburl)
|
||||
if err != nil {
|
||||
@ -37,6 +28,22 @@ func main() {
|
||||
}
|
||||
defer stor.Shutdown()
|
||||
|
||||
// If there's a backup dir specified, do backups
|
||||
// at a specific interval
|
||||
if *backupdir != "" {
|
||||
stat, err := os.Stat(*backupdir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Directory stat error: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
if !stat.IsDir() {
|
||||
fmt.Fprintf(os.Stderr, "Backup directory does not exist: %s\n", *backupdir)
|
||||
return
|
||||
}
|
||||
|
||||
go manageBackup(stor, *backupdir, *backupint)
|
||||
}
|
||||
|
||||
// Load data if asked
|
||||
if *jsonfile != "" {
|
||||
err := loadjson(stor, *jsonfile)
|
||||
|
||||
Reference in New Issue
Block a user