Skip to content

Commit

Permalink
Backup will not exit on files which does not exists (dead links)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainu committed Nov 4, 2018
1 parent 639df4e commit 8c0c12a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 71 deletions.
148 changes: 84 additions & 64 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
variables:
GITHUB_USER: rainu
GITHUB_REPO: backup2glacier
RELEASE_TAG: v0.0.1
RELEASE_TAG: v0.1.0

stages:
- build
- predeploy
- deploy
- build
- predeploy
- deploy

build-linux-386:
image: golang:1.10
stage: build
script:
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=386
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=386
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
artifacts:
paths:
- ${CI_PROJECT_DIR}/backup2glacier-*
Expand All @@ -31,16 +31,16 @@ build-linux-amd64:
image: golang:1.10
stage: build
script:
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=amd64
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=amd64
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
artifacts:
paths:
- ${CI_PROJECT_DIR}/backup2glacier-*
Expand All @@ -50,16 +50,16 @@ build-linux-arm:
image: golang:1.10
stage: build
script:
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=arm
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=arm
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
artifacts:
paths:
- ${CI_PROJECT_DIR}/backup2glacier-*
Expand All @@ -69,16 +69,16 @@ build-linux-arm64:
image: golang:1.10
stage: build
script:
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=arm64
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
- export GOPATH=$(pwd)/build
- mkdir -p build/src/
- cd build/src/
- ln -s ${CI_PROJECT_DIR} ./backup2glacier
- cd backup2glacier
- CGO_ENABLED=0
- GOOS=linux
- GOARCH=arm64
- go get ./...
- go build -a -installsuffix cgo -o backup2glacier-${GOOS}-${GOARCH} .
artifacts:
paths:
- ${CI_PROJECT_DIR}/backup2glacier-*
Expand Down Expand Up @@ -126,59 +126,79 @@ prepare-deploy-github:
image: golang:1.10
stage: predeploy
script:
- go get github.com/aktau/github-release
- github-release -v release --tag ${RELEASE_TAG} --description "automatic built builds"
- go get github.com/aktau/github-release
- github-release -v release --tag ${RELEASE_TAG} --description "automatic built builds"
only:
- master

deploy-github-linux-386:
image: golang:1.10
stage: deploy
script:
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-386 -f ${CI_PROJECT_DIR}/backup2glacier-linux-386
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-386 -f ${CI_PROJECT_DIR}/backup2glacier-linux-386
dependencies:
- build-linux-386
- build-linux-386
- prepare-deploy-github
only:
- master

deploy-github-linux-amd64:
image: golang:1.10
stage: deploy
script:
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-amd64 -f ${CI_PROJECT_DIR}/backup2glacier-linux-amd64
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-amd64 -f ${CI_PROJECT_DIR}/backup2glacier-linux-amd64
dependencies:
- build-linux-amd64
- build-linux-amd64
- prepare-deploy-github
only:
- master

deploy-github-linux-arm:
image: golang:1.10
stage: deploy
script:
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-arm -f ${CI_PROJECT_DIR}/backup2glacier-linux-arm
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-arm -f ${CI_PROJECT_DIR}/backup2glacier-linux-arm
dependencies:
- build-linux-arm
- build-linux-arm
- prepare-deploy-github
only:
- master

deploy-github-linux-arm64:
image: golang:1.10
stage: deploy
script:
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-arm64 -f ${CI_PROJECT_DIR}/backup2glacier-linux-arm64
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-linux-arm64 -f ${CI_PROJECT_DIR}/backup2glacier-linux-arm64
dependencies:
- build-linux-arm64
- build-linux-arm64
- prepare-deploy-github
only:
- master

deploy-github-windows-386:
image: golang:1.10
stage: deploy
script:
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-windows-386 -f ${CI_PROJECT_DIR}/backup2glacier-windows-386
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-windows-386 -f ${CI_PROJECT_DIR}/backup2glacier-windows-386
dependencies:
- build-windows-386
- build-windows-386
- prepare-deploy-github
only:
- master

deploy-github-windows-amd64:
image: golang:1.10
stage: deploy
script:
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-windows-amd64 -f ${CI_PROJECT_DIR}/backup2glacier-windows-amd64
- go get github.com/aktau/github-release
- github-release -v upload --tag ${RELEASE_TAG} -n backup2glacier-windows-amd64 -f ${CI_PROJECT_DIR}/backup2glacier-windows-amd64
dependencies:
- build-windows-amd64
- build-windows-amd64
- prepare-deploy-github
only:
- master
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ go build

## Release History

* 0.1.0
* Backup will not exit on files which does not exists (dead links)
* 0.0.2
* CLI Command for delete backups
* 0.0.1
Expand Down
21 changes: 14 additions & 7 deletions backup/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func Zip(filePaths []string, dst io.Writer, contentChan chan<- *ZipContent) {
absFilePath, _ := filepath.Abs(filePath)
fInfo, err := os.Stat(filePath)
if err != nil {
LogFatal("Could not read file information for '%s'. Error: %v", filePath, err)
LogError("Could not read file information for '%s'. Error: %v", filePath, err)
continue
}

if fInfo.IsDir() {
Expand All @@ -51,7 +52,8 @@ func addFiles(w *zip.Writer, basePath, baseInZip string, contentChan chan<- *Zip
// Open the Directory
files, err := ioutil.ReadDir(basePath)
if err != nil {
LogFatal("Could not list directory '%s'. Error: %v", basePath, err)
LogError("Could not list directory '%s'. Error: %v", basePath, err)
return
}

for _, fileDesc := range files {
Expand All @@ -72,7 +74,8 @@ func addFile(w *zip.Writer, basePath, baseInZip, fileName string, contentChan ch

osFile, err := os.Open(filePath)
if err != nil {
LogFatal("Could not open file '%s'. Error: %v", filePath, err)
LogError("Could not open file '%s'. Error: %v", filePath, err)
return 0
}
defer osFile.Close()

Expand All @@ -81,23 +84,27 @@ func addFile(w *zip.Writer, basePath, baseInZip, fileName string, contentChan ch
// Add some files to the archive.
fileInfo, err := osFile.Stat()
if err != nil {
LogFatal("Could not read file metadata for %s. Error: %v", filePath, err)
LogError("Could not read file metadata for %s. Error: %v", filePath, err)
return 0
}

zipFileInfo, err := zip.FileInfoHeader(fileInfo)
if err != nil {
LogFatal("Could not create fileinfo header for %s. Error: %v", zipPath, err)
LogError("Could not create fileinfo header for %s. Error: %v", zipPath, err)
return 0
}
zipFileInfo.Name = zipPath

zipFileHandle, err := w.CreateHeader(zipFileInfo)
if err != nil {
LogFatal("Could not add file '%s' to zip. Error %v", zipPath, err)
LogError("Could not add file '%s' to zip. Error %v", zipPath, err)
return 0
}

written, err := io.Copy(zipFileHandle, osFile)
if err != nil {
LogFatal("Could not add file '%s' to zip. Error %v", zipPath, err)
LogError("Could not add file '%s' to zip. Error %v", zipPath, err)
return 0
}

if contentChan != nil {
Expand Down

0 comments on commit 8c0c12a

Please sign in to comment.