Skip to content

Commit d9d1071

Browse files
fix: Update MySQL handler for size estimation and modify backup configuration
Signed-off-by: Jason Cameron <git@jasoncameron.dev>
1 parent bce8a9a commit d9d1071

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Backup system configuration
2-
#schedule = "0 4 * * *" # Daily at 4 AM
2+
#sched ule = "0 4 * * *" # Daily at 4 AM
33
temp_dir = "" # Will create a new random temp directory if not specified
44
debug = false
55

@@ -17,7 +17,8 @@ database = "myapp"
1717

1818
[filesystem]
1919
enabled = true
20-
base_path = "D:\\projects\\mcpt\\backups\\test"
20+
#base_path = "D:\\projects\\mcpt\\backups\\test"
21+
base_path = "/tmp/backups/"
2122
include_patterns = [
2223
"*.txt",
2324
"*.pdf",
@@ -32,10 +33,10 @@ exclude_patterns = [
3233
]
3334

3435
[s3]
35-
endpoint = "https://s3.amazonaws.com"
36-
region = "us-east-1"
37-
bucket = "my-backup-bucket"
38-
access_key_id = "your_access_key"
39-
secret_access_key = "your_secret_key"
36+
endpoint = "https://9ef674c7e3182148b5b136fa79415e76.r2.cloudflarestorage.com/wlmoj-backups"
37+
region = "auto"
38+
bucket = "wlmoj-backups"
39+
access_key_id = "f1867f1a5889ec3e93916bdbd940866e"
40+
secret_access_key = "eeb3b7d7c4b1273822f08cfa8484b583eab2b26ea7c5d3ff697837681898f996"
4041
max_concurrency = 10
4142
part_size=0

handlers/mysql.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (h *MySQLHandler) generateBackupFilename() string {
4848
}
4949

5050
// getTotalSize estimates the total size of the database
51-
func (h *MySQLHandler) getTotalSize(ctx context.Context) (int64, error) {
51+
func (h *MySQLHandler) getTotalSize(ctx context.Context) int64 {
5252
cmd := exec.CommandContext(ctx, "mariadb", // #nosec G204 -- All data here is coming from the config file,
5353
// which if someone can modify, they can do anything they want
5454
"--skip-column-names",
@@ -60,21 +60,19 @@ func (h *MySQLHandler) getTotalSize(ctx context.Context) (int64, error) {
6060
fmt.Sprintf("-p%s", config.Cfg.MySQL.Password),
6161
"-e 'SELECT ROUND(SUM(data_length) * 0.8) AS \"size_bytes\" FROM information_schema.TABLES;'",
6262
)
63-
output, err := cmd.Output()
64-
fmt.Println(cmd.String())
65-
66-
if err != nil {
67-
return 0, &ErrMySQLBackup{Op: "size estimation", Err: err}
68-
}
63+
output, _ := cmd.Output()
6964

7065
sizeStr := string(bytes.TrimSpace(output))
66+
if sizeStr == "" {
67+
return 564009370 // Default size if no output
68+
}
7169
size, err := strconv.ParseInt(sizeStr, 10, 64)
7270
if err != nil {
73-
fmt.Println("Failed to convert size string to int64", err)
71+
fmt.Println("Failed to convert size string to int64", err, "size: ", sizeStr)
7472
// Fallback to a default size if parsing fails
75-
return 563091866, nil
73+
return 564009370
7674
}
77-
return size, nil
75+
return size
7876
}
7977

8078
// createMySQLDumpCommand creates the mysqldump command with proper parameters
@@ -111,11 +109,9 @@ func (h *MySQLHandler) Backup(ctx context.Context) (string, error) {
111109
}()
112110

113111
// Get total size for progress bar
114-
totalSize, err := h.getTotalSize(ctx)
115-
if err != nil {
116-
// Log the error but continue with default size
117-
fmt.Printf("Warning: Failed to get total size: %v\n", err)
118-
}
112+
totalSize := h.getTotalSize(ctx)
113+
114+
fmt.Printf("Total size of the database: %d\n", totalSize)
119115

120116
// Create progress bar
121117
bar := progressbar.DefaultBytes(

0 commit comments

Comments
 (0)