commit
c29547d3de
2 changed files with 9 additions and 15 deletions
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
|
|
@ -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 }}
|
||||||
|
|
|
||||||
|
|
@ -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())
|
||||||
}
|
}
|
||||||
Reference in a new issue