keep backups of the config files

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-24 09:27:23 -05:00
parent acdd6e9c5b
commit aa742d099d
3 changed files with 21 additions and 13 deletions

View File

@ -10,8 +10,7 @@ all:
./virtigo --help
xml-add:
./virtigo --add-xml /home/nfs3/xml/*.xml
# ./virtigo --add-xml /etc/libvirt/qemu/*xml
./virtigo --add-xml /tmp/xml/*.xml
start-all-droplets:
curl --silent http://localhost:8080/start?start=git.wit.org

10
argv.go
View File

@ -11,12 +11,12 @@ import "go.wit.com/log"
var argv args
type args struct {
Dir string `arg:"--dir" help:"defaults to ~/.config/virtigo/"`
Port int `arg:"--port" default:"8080" help:"specify a different default port"`
Xml []string `arg:"--add-xml" help:"add libvirt xml files"`
CfgDir string `arg:"--dir" help:"defaults to ~/.config/virtigo/"`
Hosts []string `arg:"--hosts" help:"hosts to connect to"`
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`
Daemon bool `arg:"--daemon" help:"run in daemon mode"`
Xml []string `arg:"--add-xml" help:"add libvirt xml files"`
Save bool `arg:"--save" default:"false" help:"save xml changes to the protobuf values"`
}
@ -24,7 +24,9 @@ func (a args) Description() string {
return `
virtigo will help control your cluster of hypervisiors
go install go.wit.com/apps/virtigo@latest
This maintains a master list of all your vm's (aka 'droplets')
in your homelab cloud. You can import libvirt xml files.
This app talks to your hypervisors via the virtigod daemon.
`
}

View File

@ -84,12 +84,14 @@ func readConfigFile(filename string) error {
}
func writeConfigFile() {
test := time.Now().Format("YYYYMMDD-HH-MM")
if !writeConfigFileTmp("virtigo.json.new." + test) {
log.Println("config file write error")
os.Exit(-1)
}
if !writeConfigFileTmp("virtigo.json") {
// Get the current time
now := time.Now()
// Format the time to match your desired format: YYYY.MM.DD.HHMMSS
timestamp := now.Format("2006.01.02.150405")
filename := "virtigo.json.new." + timestamp
if !writeConfigFileTmp(filename) {
log.Println("config file write error")
os.Exit(-1)
}
@ -101,10 +103,15 @@ func writeConfigFile() {
log.Printf("rename fail: %s", err)
os.Exit(-1)
}
if !writeConfigFileTmp("virtigo.json") {
log.Println("config file write error")
os.Exit(-1)
}
}
func writeConfigFileTmp(filename string) bool {
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), "virtigo.json")
fullname := filepath.Join(os.Getenv("VIRTIGO_HOME"), filename)
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()
if err != nil {