Compress then remove files
This commit is contained in:
parent
7f2030edbb
commit
20e39439e4
|
@ -17,10 +17,10 @@ date_year="2019"
|
||||||
date_start="${date_year}-01-01 00:00:01"
|
date_start="${date_year}-01-01 00:00:01"
|
||||||
date_end="${date_year}-12-31 23:59:59"
|
date_end="${date_year}-12-31 23:59:59"
|
||||||
|
|
||||||
## Best XZ compression level (= -9)
|
## Best XZ compression level
|
||||||
xz_compression_lvl="--best"
|
xz_compression_lvl="-9"
|
||||||
## Fatest XZ compression level (= -0)
|
## Fatest XZ compression level
|
||||||
#xz_compression_lvl="--fast"
|
#xz_compression_lvl="-0"
|
||||||
|
|
||||||
## Get current directory name
|
## Get current directory name
|
||||||
current_dir=${PWD##*/}
|
current_dir=${PWD##*/}
|
||||||
|
@ -30,6 +30,16 @@ tar_file_name="${date_year}.${current_dir}.tar.xz"
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
[ "${debug}" -eq "0" ] && printf '%b' "Create an archive for ${current_dir} files between ${date_start} and ${date_end} using XZ's compression level : ${xz_compression_lvl}."
|
[ "${debug}" -eq "0" ] && printf '%b\n' "Create an archive for ${current_dir} files between ${date_start} and ${date_end} using XZ's compression level : ${xz_compression_lvl}."
|
||||||
|
|
||||||
|
## Get the list of files between the 2 dates and ignore tar files
|
||||||
|
find . -type f -newermt "${date_start}" -not -newermt "${date_end}" -not -iname "*.tar*" -print0 | tar cJf "${tar_file_name}" --null -T -
|
||||||
|
|
||||||
|
## Check previous return code and if the archive exists with size > 0
|
||||||
|
if [ "${?}" -eq "0" ] && [ -s "${tar_file_name}" ]; then
|
||||||
|
[ "${debug}" -eq "0" ] && printf '%b\n' "${tar_file_name} successfully created, the files can be deleted."
|
||||||
|
find . -type f -newermt "${date_start}" -not -newermt "${date_end}" -not -iname "*.tar*" -delete
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue