summaryrefslogtreecommitdiff
path: root/backup.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-27 06:05:49 -0500
committerJeff Carr <[email protected]>2024-10-27 06:05:49 -0500
commit3a9e77a4fb25bea7de28a29300c5ab032e6d4765 (patch)
tree835922ad0e61f474b896525838d0036cbd4c47ee /backup.go
parentdc2dba26556d507bc929056755395cc51fcc7d9e (diff)
backup the cluster config files
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'backup.go')
-rw-r--r--backup.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/backup.go b/backup.go
new file mode 100644
index 0000000..adaa99c
--- /dev/null
+++ b/backup.go
@@ -0,0 +1,66 @@
+package virtbuf
+
+// thank chatgpt for this because why. why write this if you can have it
+// kick this out in 30 seconds
+
+import (
+ "io"
+ "log"
+ "os"
+ "path/filepath"
+)
+
+func backupFiles(srcDir string, destDir string) error {
+ // Create the destination directory
+ err := os.MkdirAll(destDir, os.ModePerm)
+ if err != nil {
+ log.Println("Failed to create directory: %v", err)
+ return err
+ }
+
+ // Walk through the source directory
+ err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return err
+ }
+
+ // Skip if it's not a .test file or if it's a directory
+ if filepath.Ext(path) != ".json" || info.IsDir() {
+ return nil
+ }
+
+ // Destination file path
+ destPath := filepath.Join(destDir, info.Name())
+
+ // Copy the file
+ if err := copyFile(path, destPath); err != nil {
+ return err
+ }
+ return nil
+ })
+
+ if err != nil {
+ log.Println("Failed to copy files: %v", err)
+ return err
+ }
+ return nil
+}
+
+// copyFile copies a file from src to dest
+func copyFile(src, dest string) error {
+ srcFile, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer srcFile.Close()
+
+ destFile, err := os.Create(dest)
+ if err != nil {
+ return err
+ }
+ defer destFile.Close()
+
+ // Copy the content
+ _, err = io.Copy(destFile, srcFile)
+ return err
+}