Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
fcbaaa092f
2 changed files with 33 additions and 5 deletions
12
README.md
12
README.md
|
|
@ -4,15 +4,19 @@ Please keep in mind that this project is WIP.
|
||||||
|
|
||||||
## What can it do?
|
## What can it do?
|
||||||
- Backup you stuff via a dynamic configuration (done!)
|
- 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))
|
- Upload the files to a remote storage of your choice (see [Storage Types](#storage-types))
|
||||||
|
|
||||||
|
|
||||||
## Database Types
|
## Database Types
|
||||||
- MariaDB (soon)
|
- MariaDB (done!)
|
||||||
- MySQL (far future)
|
- MySQL (soon)
|
||||||
- MS-SQL (far future)
|
- MS-SQL (far future)
|
||||||
|
|
||||||
|
| Database Type | Config Type |
|
||||||
|
|-------------------|---------------------------|
|
||||||
|
| MariaDB | mariadb |
|
||||||
|
|
||||||
|
|
||||||
## Storage types
|
## Storage types
|
||||||
- Local storage (soon)
|
- Local storage (soon)
|
||||||
|
|
@ -35,7 +39,7 @@ Please keep in mind that this project is WIP.
|
||||||
|---------------------|:----------------:|------------------------------------------------|
|
|---------------------|:----------------:|------------------------------------------------|
|
||||||
| localBackupPath | string | Path where local backups are stored |
|
| localBackupPath | string | Path where local backups are stored |
|
||||||
| **sqlConfig** | ---------------- | ---------------------------------------------- |
|
| **sqlConfig** | ---------------- | ---------------------------------------------- |
|
||||||
| sqlType | string | SQL Server Type (not yet used) |
|
| sqlType | string | See [DatabaseTypes](#database-types) |
|
||||||
| sql-address | string | Address to the SQL Server |
|
| sql-address | string | Address to the SQL Server |
|
||||||
| sql-port | uint16 | SQL Server Port |
|
| sql-port | uint16 | SQL Server Port |
|
||||||
| database | string | Database name |
|
| database | string | Database name |
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,12 @@ func checkIfBackupTableExist(db *sql.DB, mariadb MariaDBConnector) bool {
|
||||||
return true
|
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{
|
func createMariaDBConnection(mariadb MariaDBConnector) *sql.DB{
|
||||||
logger := Logging.DetailedLogger("MariaDB", "createConnection")
|
logger := Logging.DetailedLogger("MariaDB", "createConnection")
|
||||||
db, err := sql.Open("mysql", mariadb.DbUser + ":" + mariadb.DbPassword + "@(" + mariadb.Address + ":" +strconv.Itoa(int(mariadb.Port))+ ")/" + mariadb.Database)
|
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){}
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue