Skip to content

Commit

Permalink
Silent lock and use flag
Browse files Browse the repository at this point in the history
  • Loading branch information
PATROMO committed May 16, 2023
1 parent c842c64 commit 70e3dbb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"flag"
"fmt"
"github.com/nightlyone/lockfile"
"os"
Expand Down Expand Up @@ -53,14 +54,24 @@ func xtrabackup(targetDir string, incrementalBasedir string) {
}
}

var silentLock bool

func init() {
flag.BoolVar(&silentLock, "silent-lock", false, "")
}

func main() {
flag.Parse()

lock, err := lockfile.New(filepath.Join(os.TempDir(), "easybackup.pid"))
if err != nil {
panic(err)
}

if err = lock.TryLock(); err != nil {
if silentLock {
return
}
panic(err)
}

Expand All @@ -71,8 +82,8 @@ func main() {
}()

var backupDir string
if os.Args != nil && len(os.Args) > 1 {
backupDir = os.Args[1]
if len(flag.Args()) > 0 {
backupDir = flag.Args()[0]
if _, err := os.Stat(backupDir); os.IsPermission(err) || os.IsNotExist(err) {
panic(err)
}
Expand Down

0 comments on commit 70e3dbb

Please sign in to comment.