From d01230c2c8364ac3af6cde22b910caf0183753f3 Mon Sep 17 00:00:00 2001 From: netbenix Date: Tue, 23 Nov 2021 09:40:33 +0100 Subject: [PATCH 1/2] Updated README.md --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 86ec1f9..f1c1107 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,19 @@ Please keep in mind that this project is WIP. ## What can it do? - Backup you stuff via a dynamic configuration (done!) -- Log the Backup progress to a database (planned) +- Log the Backup progress to a database (in progress) - Upload the files to a remote storage of your choice (see [Storage Types](#storage-types)) ## Database Types -- MariaDB (soon) -- MySQL (far future) +- MariaDB (done!) +- MySQL (soon) - MS-SQL (far future) +| Database Type | Config Type | +|-------------------|---------------------------| +| MariaDB | mariadb | + ## Storage types - Local storage (soon) @@ -35,7 +39,7 @@ Please keep in mind that this project is WIP. |---------------------|:----------------:|------------------------------------------------| | localBackupPath | string | Path where local backups are stored | | **sqlConfig** | ---------------- | ---------------------------------------------- | -| sqlType | string | SQL Server Type (not yet used) | +| sqlType | string | See [DatabaseTypes](#database-types) | | sql-address | string | Address to the SQL Server | | sql-port | uint16 | SQL Server Port | | database | string | Database name | From a22a73cc933f0cc96333a24dd224581ea66cd359 Mon Sep 17 00:00:00 2001 From: netbenix Date: Tue, 23 Nov 2021 12:29:45 +0100 Subject: [PATCH 2/2] Implemented newBackupEntry for MariaDB --- SQL/MariaDBConnector.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/SQL/MariaDBConnector.go b/SQL/MariaDBConnector.go index bd4b0c4..bff477f 100644 --- a/SQL/MariaDBConnector.go +++ b/SQL/MariaDBConnector.go @@ -43,6 +43,12 @@ func checkIfBackupTableExist(db *sql.DB, mariadb MariaDBConnector) bool { return true } +func checkIfBackupEntryExist(db *sql.DB, mariadb MariaDBConnector, backupName string) bool { + rows, _ := db.Query("SELECT * FROM `" + mariadb.Database + "`.Backups WHERE BackupName = '" + backupName + "';") + if !rows.Next(){ return false; } + return true +} + func createMariaDBConnection(mariadb MariaDBConnector) *sql.DB{ logger := Logging.DetailedLogger("MariaDB", "createConnection") db, err := sql.Open("mysql", mariadb.DbUser + ":" + mariadb.DbPassword + "@(" + mariadb.Address + ":" +strconv.Itoa(int(mariadb.Port))+ ")/" + mariadb.Database) @@ -89,4 +95,22 @@ func (mariadb MariaDBConnector) newLogEntry(uuid uuid.UUID, logType LogType, bac } } -func (mariadb MariaDBConnector) newBackupEntry(uuid uuid.UUID, backupName string, lastBackup time.Time, localBackup bool, filePath string, storageType RemoteStorageType, remotePath string, durationToBackup time.Duration, hadErrors bool){} \ No newline at end of file + + +func (mariadb MariaDBConnector) newBackupEntry(uuid uuid.UUID, backupName string, lastBackup time.Time, localBackup bool, filePath string, storageType RemoteStorageType, remotePath string, durationToBackup time.Duration, hadErrors bool){ + logger := Logging.DetailedLogger("MariaDB", "newBackupEntry") + + db := createMariaDBConnection(mariadb) + + if checkIfBackupEntryExist(db, mariadb, backupName){ + _, err := db.Query("UPDATE `" + mariadb.Database + "`.Backups SET LastBackup = ?, `DurationToBackup (s)` = ?, HadErrors = ? WHERE BackuoName = ?;",lastBackup, durationToBackup, hadErrors, backupName) + if err != nil { + logger.Fatal(err) + } + } else { + _, err := db.Query("INSERT INTO `" + mariadb.Database + "`.Backups VALUES (?, ?, ?, ?, ?, ?, ?, ?);", uuid.String(), lastBackup, localBackup, filePath, strconv.FormatInt(int64(storageType), 10), remotePath, durationToBackup, hadErrors) + if err != nil { + logger.Fatal(err) + } + } +} \ No newline at end of file