Merge pull request #6 from netbenix/develop

Updated Compression
This commit is contained in:
netbenix 2021-11-28 13:55:45 +01:00 committed by GitHub
commit c29547d3de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 15 deletions

View file

@ -20,14 +20,14 @@ jobs:
- name: Bump version and push tag - name: Bump version and push tag
id: tag_version id: tag_version
uses: mathieudutour/github-tag-action@v5.6 uses: mathieudutour/github-tag-action@v5.6
env:
default_bump: minor
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release - name: Create Release
id: create_release id: create_release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ steps.tag_version.outputs.changelog }} body: ${{ steps.tag_version.outputs.changelog }}

View file

@ -2,7 +2,6 @@ package Compressor
import ( import (
"archive/tar" "archive/tar"
"bytes"
"compress/flate" "compress/flate"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
@ -18,9 +17,6 @@ import (
func CreateBakFile(fileName string, folderPath string, destinationPath string, backupName string) string { func CreateBakFile(fileName string, folderPath string, destinationPath string, backupName string) string {
logger := Logging.DetailedLogger("Compression", "CreateBakFile") logger := Logging.DetailedLogger("Compression", "CreateBakFile")
var buf bytes.Buffer
compress(folderPath, &buf, backupName)
pathToFile := destinationPath + string(os.PathSeparator) + fileName + ".bak" pathToFile := destinationPath + string(os.PathSeparator) + fileName + ".bak"
@ -28,10 +24,8 @@ func CreateBakFile(fileName string, folderPath string, destinationPath string, b
if err != nil { if err != nil {
logger.Fatal(err) logger.Fatal(err)
} }
compress(fileToWrite, folderPath, backupName)
if _, err := io.Copy(fileToWrite, &buf); err != nil {
logger.Fatal(err)
}
SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, backupName, SQL.SQLStage_Compress, SQL.REMOTE_NONE, "File successfully written.", time.Now()) SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, backupName, SQL.SQLStage_Compress, SQL.REMOTE_NONE, "File successfully written.", time.Now())
@ -39,14 +33,13 @@ func CreateBakFile(fileName string, folderPath string, destinationPath string, b
return fileName return fileName
} }
func compress(fileToWrite *os.File, folderPath string, backupName string){
func compress(folderPath string, buf io.Writer, backupName string){
logger := Logging.DetailedLogger("Gzip", "compress") logger := Logging.DetailedLogger("Gzip", "compress")
zr, _ := gzip.NewWriterLevel(buf, flate.BestCompression) zr, _ := gzip.NewWriterLevel(fileToWrite, flate.BestCompression)
tw := tar.NewWriter(zr) tw := tar.NewWriter(zr)
fmt.Printf("[%s] Start compression...\n", filepath.Base(folderPath)) go fmt.Printf("[%s] Start compression...\n", filepath.Base(folderPath))
SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, backupName, SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Start compression", time.Now()) SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, backupName, SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Start compression", time.Now())
filepath.Walk(folderPath, func(file string, fi os.FileInfo, err error) error { filepath.Walk(folderPath, func(file string, fi os.FileInfo, err error) error {
header, err := tar.FileInfoHeader(fi, file) header, err := tar.FileInfoHeader(fi, file)
@ -67,11 +60,12 @@ func compress(folderPath string, buf io.Writer, backupName string){
logger.Fatal(err) logger.Fatal(err)
} }
fmt.Printf("[%s] Compressing: %s (%d bytes)\n", filepath.Base(folderPath) ,relPath, fi.Size()) go fmt.Printf("[%s] Compressing: %s (%d bytes)\n", filepath.Base(folderPath) ,relPath, fi.Size())
if _, err := io.Copy(tw, data); err != nil { if _, err := io.Copy(tw, data); err != nil {
logger.Fatal(err) logger.Fatal(err)
} }
} }
return nil return nil
}) })
@ -84,6 +78,6 @@ func compress(folderPath string, buf io.Writer, backupName string){
} }
fmt.Printf("[%s] Compression Done.\n", filepath.Base(folderPath)) go fmt.Printf("[%s] Compression Done.\n", filepath.Base(folderPath))
SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, backupName, SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Compression complete.", time.Now()) SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, backupName, SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Compression complete.", time.Now())
} }