1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package main
- import (
- "fmt"
- "os"
- "io/ioutil"
- "time"
- "strings"
- "github.com/FossoresLP/go-uuid-v4"
- )
- func main() {
- //Take in setup cofiguration from the backup.config
- //Check if the file exists or not
- if _, err := os.Stat("../backup.config"); os.IsNotExist(err) {
- // path/to/whatever does not exist
- fmt.Println("ERROR. Configuration file not found.");
- os.Exit(1)
- }
- //Configuration exists. Start reading content from config
- b, err := ioutil.ReadFile("../backup.config") // just pass the file name
- if err != nil {
- fmt.Print(err)
- os.Exit(1)
- }
- //The content is loaded into the b variable
- rawConfigs := strings.Replace(string(b),"\r\n","\n",-1)
- configs := strings.Split(rawConfigs, "\n")
- for i:=0; i < len(configs); i++{
- fmt.Println(configs[i] + "///")
- }
- //Define backup permeters. If it is not defined in the config, use default instead.
- //root := "../../../"
- //useExt := false
- useUUID := false
- t := time.Now()
- backupName := t.Format("20060102150405")
- if (useUUID){
- backupName, _ = uuid.NewString()
- }
- //Define the default backup directory. Make directory if not exists
- storeDir := "backups/"
- if _, err := os.Stat(storeDir); os.IsNotExist(err) {
- os.Mkdir(storeDir, 0777)
- }
-
- fmt.Println(backupName)
- }
|