Browse Source

Implement backup size for details and status lists

master
Bernhard Fröhlich 8 months ago
parent
commit
22b02eb679
Signed by: Bernhard Froehlich <decke@bluelife.at> GPG Key ID: 4DD88C3F9F3B8333
5 changed files with 40 additions and 14 deletions
  1. 12
    6
      lib/core
  2. 4
    2
      lib/core-rsync
  3. 7
    4
      lib/core-rsynczfs
  4. 3
    2
      lib/core-sftp
  5. 14
    0
      lib/util

+ 12
- 6
lib/core View File

@@ -119,14 +119,14 @@ core__pull(){
#
core__status(){
local _outdated_only
local _host _type _line _fqdn _backup _timestamp _date_diff _date_str
local _host _type _line _fqdn _backup _timestamp _date_diff _date_str _formattedsize
local _datediff_max

[ "$1" = "-i" ] && _outdated_only="y"

# pass everything below here to column(1)
{
printf "%s^%b\n" "NAME" "LAST BACKUP"
printf "%s^%s^%b\n" "NAME" "SIZE" "LAST BACKUP"

ls -1 "${ssbt_dir}" 2>/dev/null | awk -F . '{ b=$9 FS $8 FS $7 FS $6 FS $5 FS $4 FS $3 FS $2 FS $1; gsub(/^[.]+/, "", b); print b}' | sort | \
while read _fqdn; do
@@ -154,8 +154,10 @@ core__status(){
_date_str="none"
fi

_formattedsize=`du -hs "${ssbt_dir}/${_host}/" | cut -f1 | xargs`

if [ -z "${_outdated_only}" -o ${_date_diff} -gt ${_datediff_max} ]; then
printf "%s^%b\n" "${_fqdn}" "${_date_str}"
printf "%s^%s^%b\n" "${_fqdn}" "${_formattedsize}" "${_date_str}"
fi
done
} | column -ts^
@@ -166,7 +168,7 @@ core__status(){
core__details(){
local _host="$1" _type _frequ _remote_user _remote_dir _local_user _local_group
local _keep_daily _keep_weekly _rsync_flags _prepull_cmd _postpull_cmd
local _line _backup _timestamp
local _line _backup _timestamp _size _formatteddate _formattedsize

[ -z "${_host}" ] && util__err "Parameter host needs to be set"
[ ! -d "${ssbt_dir}/${_host}" ] && util__err "Host ${_host} does not exist"
@@ -214,14 +216,18 @@ core__details(){

# pass everything below here to column(1)
{
printf "%s^%s\n" "BACKUP" "BACKUP DATE"
printf "%s^%s^%s\n" "BACKUP" "BACKUP DATE" "BACKUP SIZE"

core__${_type}__list "${_host}" | \
while read _line; do
_backup=`echo "${_line}" | cut -d^ -f1`
_timestamp=`echo "${_line}" | cut -d^ -f2`
_size=`echo "${_line}" | cut -d^ -f3`

_formatteddate=`util__dateformat "${_timestamp}" "+%Y/%m/%d %H:%M"`
_formattedsize=`util__numberformat "${_size}"`

printf "%s^%s\n" "${_backup}" "`util__dateformat "${_timestamp}" "+%Y/%m/%d %H:%M"`"
printf "%s^%s^%s\n" "${_backup}" "${_formatteddate}" "${_formattedsize}"
done
} | column -ts^
}

+ 4
- 2
lib/core-rsync View File

@@ -52,7 +52,7 @@ core__rsync__pull(){
# List local backups (youngest first)
#
core__rsync__list(){
local _host="$1" _backup _timestamp _file _remote_dir
local _host="$1" _backup _timestamp _file _remote_dir _size

_file="${ssbt_dir}/${_host}/.ssbt-lastsync"

@@ -60,7 +60,9 @@ core__rsync__list(){

config__get "_remote_dir" "remote_dir" "/data"

printf "%s^%s\n" "${_remote_dir}" "`date -j -r "${_file}" +"%Y%m%d%H%M"`"
_size=`du -hs "${ssbt_dir}/${_host}/"`

printf "%s^%s^%s\n" "${_remote_dir}" "`date -j -r "${_file}" +"%Y%m%d%H%M"`" "${_size}"
}

# Remove backup

+ 7
- 4
lib/core-rsynczfs View File

@@ -65,15 +65,18 @@ core__rsynczfs__pull(){
# List local backups (youngest first)
#
core__rsynczfs__list(){
local _host="$1" _filesystem _snapshot _timestamp
local _host="$1" _filesystem _snapshot _timestamp _size

_filesystem=`core__rsynczfs__getfs "${_host}"`

zfs list -Hp -t snapshot -o name -r "${_filesystem}" | sort -r | \
while read _snapshot; do
zfs list -Hp -t snapshot -o name,used -r "${_filesystem}" | sort -r | \
while read _line; do
_snapshot=`echo "${_line}" | cut -f1`
_size=`echo "${_line}" | cut -f2`

_timestamp="${_snapshot##*@}"

printf "%s^%s\n" "${_snapshot}" "${_timestamp}"
printf "%s^%s^%s\n" "${_snapshot}" "${_timestamp}" "${_size}"
done
}


+ 3
- 2
lib/core-sftp View File

@@ -96,14 +96,15 @@ core__sftp__pull(){
# List local backed up files (youngest first)
#
core__sftp__list(){
local _host="$1" _file _timestamp
local _host="$1" _file _timestamp _size

ls -1r "${ssbt_dir}/${_host}" | grep -v ".ssbt." | grep -v ".sha256" 2>/dev/null | \
while read _file; do
_timestamp=${_file##*-}
_timestamp=${_timestamp%%.*}
_size=`stat -f %z "${ssbt_dir}/${_host}/${_file}"`

printf "%s^%s\n" "${_file}" "${_timestamp}"
printf "%s^%s^%d\n" "${_file}" "${_timestamp}" "${_size}"
done
}


+ 14
- 0
lib/util View File

@@ -220,3 +220,17 @@ util__dateformat(){
date -j "${_date}${_time}" "${_format}"
fi
}

util__numberformat(){
local _size="$1"
local _units="B KiB MiB GiB TiB PiB"
local _unit

for X in ${_units}; do
_unit=$X
test ${_size%.*} -lt 1024 && break;
_size=`echo "${_size} / 1024" | bc -l`
done

printf "%.1f %s\n" ${_size} ${_unit}
}

Loading…
Cancel
Save