mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-06 21:49:40 +01:00
refactor: clean up code
This commit is contained in:
@@ -141,13 +141,9 @@ func BackupDatabase(disableCompression bool, prune bool, keepLast int) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
utils.Done("Database has been backed up")
|
utils.Done("Database has been backed up")
|
||||||
|
|
||||||
utils.Info(keepLast)
|
|
||||||
utils.Info(prune)
|
|
||||||
|
|
||||||
//Delete old backup
|
//Delete old backup
|
||||||
if prune {
|
if prune {
|
||||||
cleanBackup(keepLast)
|
deleteOldBackup(keepLast)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -170,7 +166,7 @@ func s3Backup(disableCompression bool, s3Path string, prune bool, keepLast int)
|
|||||||
BackupDatabase(disableCompression, prune, keepLast)
|
BackupDatabase(disableCompression, prune, keepLast)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanBackup(keepLast int) {
|
func deleteOldBackup(keepLast int) {
|
||||||
utils.Info("Deleting old backups...")
|
utils.Info("Deleting old backups...")
|
||||||
storagePath = os.Getenv("STORAGE_PATH")
|
storagePath = os.Getenv("STORAGE_PATH")
|
||||||
// Define the directory path
|
// Define the directory path
|
||||||
@@ -184,7 +180,6 @@ func cleanBackup(keepLast int) {
|
|||||||
}
|
}
|
||||||
// Check if the file is older than defined day days
|
// Check if the file is older than defined day days
|
||||||
if info.Mode().IsRegular() && info.ModTime().Before(currentTime.AddDate(0, 0, -keepLast)) {
|
if info.Mode().IsRegular() && info.ModTime().Before(currentTime.AddDate(0, 0, -keepLast)) {
|
||||||
//if info.Mode().IsRegular() && info.ModTime().Before(currentTime.Add(+2*time.Minute)) {
|
|
||||||
// Remove the file
|
// Remove the file
|
||||||
err := os.Remove(path)
|
err := os.Remove(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user