Skip to content

Commit

Permalink
Merge pull request #13 from hmerritt/v0.2.1
Browse files Browse the repository at this point in the history
Improvements
- Recursively create backup folder location

Tweaks
- Remove item name from current task
  • Loading branch information
hmerritt authored Apr 25, 2020
2 parents 7e73c6f + 3bf63ab commit e0b87e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions src/modules/files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,44 @@ isdirectory () {
## - $3: directory of the backup location
backup () {

## Get args | use fallback values
item_name=$(fallback "${1}" "")
item_dir_local=$(fallback "${2}" "/")
item_dir_backup=$(fallback "${3}" "${item_dir_local}")
## Get args | use fallback values
local item_name=$(fallback "${1}" "")
local item_dir_local=$(fallback "${2}" "/")
local item_dir_backup=$(fallback "${3}" "${item_dir_local}")

action "Backing up ${item_name}"

## Set folder locations
local tmp_folder="/var/tmp"
local tmp_file="${tmp_folder}/${item_name}"
local dir_local="${DIR_ROOT_LOCAL}${item_dir_local}"
local dir_backup="${DIR_ROOT_BACKUP}${item_dir_backup}"

## If root folder exists
## Use absolute file paths
if [ "${DIR_ROOT_LOCAL}" != "" ] || [ "${item_dir_local}" != "" ]; then
cd "${DIR_ROOT_LOCAL}${item_dir_local}" || onfail "" "Error opening directory '${DIR_ROOT_LOCAL}${item_dir_local}'"
cd "${dir_local}" || \
onfail "" "Error opening directory '${dir_local}'"
fi

task "Compressing ${item_name}"
## Tar.gz item
task "Compressing"
compress "${tmp_file}" "${item_name}" & spinner
onfail

task "Moving ${item_name} to backup location"
move "${tmp_file}.tar.gz" "${DIR_ROOT_BACKUP}${item_dir_backup}${item_name}.tar.gz" & spinner
## If backup folder does not exist
if ! isdirectory "${dir_backup}"; then
## Create backup folder location
task "Creating backup location"
mkdir -p "${dir_backup}" & spinner
onfail
fi

## Move item from tmp/ to backup location
task "Moving to backup location"
move "${tmp_file}.tar.gz" "${dir_backup}${item_name}.tar.gz" & spinner
onfail

green "Completed: ${item_name}"

}
2 changes: 1 addition & 1 deletion src/modules/global.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash


VERSION="0.2.0"
VERSION="0.2.1"


##------------------------------------------------------------------------------
Expand Down

0 comments on commit e0b87e0

Please sign in to comment.