main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "io/ioutil"
  6. "time"
  7. "strings"
  8. "github.com/FossoresLP/go-uuid-v4"
  9. )
  10. func main() {
  11. //Take in setup cofiguration from the backup.config
  12. //Check if the file exists or not
  13. if _, err := os.Stat("../backup.config"); os.IsNotExist(err) {
  14. // path/to/whatever does not exist
  15. fmt.Println("ERROR. Configuration file not found.");
  16. os.Exit(1)
  17. }
  18. //Configuration exists. Start reading content from config
  19. b, err := ioutil.ReadFile("../backup.config") // just pass the file name
  20. if err != nil {
  21. fmt.Print(err)
  22. os.Exit(1)
  23. }
  24. //The content is loaded into the b variable
  25. rawConfigs := strings.Replace(string(b),"\r\n","\n",-1)
  26. configs := strings.Split(rawConfigs, "\n")
  27. for i:=0; i < len(configs); i++{
  28. fmt.Println(configs[i] + "///")
  29. }
  30. //Define backup permeters. If it is not defined in the config, use default instead.
  31. //root := "../../../"
  32. //useExt := false
  33. useUUID := false
  34. t := time.Now()
  35. backupName := t.Format("20060102150405")
  36. if (useUUID){
  37. backupName, _ = uuid.NewString()
  38. }
  39. //Define the default backup directory. Make directory if not exists
  40. storeDir := "backups/"
  41. if _, err := os.Stat(storeDir); os.IsNotExist(err) {
  42. os.Mkdir(storeDir, 0777)
  43. }
  44. fmt.Println(backupName)
  45. }