Browse Source

Implement backup size for details and status lists

Bernhard Fröhlich 2 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(){
119 119
 #
120 120
 core__status(){
121 121
     local _outdated_only
122
-    local _host _type _line _fqdn _backup _timestamp _date_diff _date_str
122
+    local _host _type _line _fqdn _backup _timestamp _date_diff _date_str _formattedsize
123 123
     local _datediff_max
124 124
 
125 125
     [ "$1" = "-i" ] && _outdated_only="y"
126 126
 
127 127
     # pass everything below here to column(1)
128 128
     {
129
-        printf "%s^%b\n" "NAME" "LAST BACKUP"
129
+        printf "%s^%s^%b\n" "NAME" "SIZE" "LAST BACKUP"
130 130
 
131 131
         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 | \
132 132
         while read _fqdn; do
@@ -154,8 +154,10 @@ core__status(){
154 154
                 _date_str="none"
155 155
             fi
156 156
 
157
+            _formattedsize=`du -hs "${ssbt_dir}/${_host}/" | cut -f1 | xargs`
158
+
157 159
             if [ -z "${_outdated_only}" -o ${_date_diff} -gt ${_datediff_max} ]; then
158
-                printf "%s^%b\n" "${_fqdn}" "${_date_str}"
160
+                printf "%s^%s^%b\n" "${_fqdn}" "${_formattedsize}" "${_date_str}"
159 161
             fi
160 162
         done
161 163
     } | column -ts^
@@ -166,7 +168,7 @@ core__status(){
166 168
 core__details(){
167 169
     local _host="$1" _type _frequ _remote_user _remote_dir _local_user _local_group
168 170
     local _keep_daily _keep_weekly _rsync_flags _prepull_cmd _postpull_cmd
169
-    local _line _backup _timestamp
171
+    local _line _backup _timestamp _size _formatteddate _formattedsize
170 172
 
171 173
     [ -z "${_host}" ] && util__err "Parameter host needs to be set"
172 174
     [ ! -d "${ssbt_dir}/${_host}" ] && util__err "Host ${_host} does not exist"
@@ -214,14 +216,18 @@ core__details(){
214 216
 
215 217
     # pass everything below here to column(1)
216 218
     {
217
-        printf "%s^%s\n" "BACKUP" "BACKUP DATE"
219
+        printf "%s^%s^%s\n" "BACKUP" "BACKUP DATE" "BACKUP SIZE"
218 220
 
219 221
         core__${_type}__list "${_host}" | \
220 222
         while read _line; do
221 223
             _backup=`echo "${_line}" | cut -d^ -f1`
222 224
             _timestamp=`echo "${_line}" | cut -d^ -f2`
225
+            _size=`echo "${_line}" | cut -d^ -f3`
226
+
227
+            _formatteddate=`util__dateformat "${_timestamp}" "+%Y/%m/%d %H:%M"`
228
+            _formattedsize=`util__numberformat "${_size}"`
223 229
 
224
-            printf "%s^%s\n" "${_backup}" "`util__dateformat "${_timestamp}" "+%Y/%m/%d %H:%M"`"
230
+            printf "%s^%s^%s\n" "${_backup}" "${_formatteddate}" "${_formattedsize}"
225 231
         done
226 232
     } | column -ts^
227 233
 }

+ 4
- 2
lib/core-rsync View File

@@ -52,7 +52,7 @@ core__rsync__pull(){
52 52
 # List local backups (youngest first)
53 53
 #
54 54
 core__rsync__list(){
55
-    local _host="$1" _backup _timestamp _file _remote_dir
55
+    local _host="$1" _backup _timestamp _file _remote_dir _size
56 56
 
57 57
     _file="${ssbt_dir}/${_host}/.ssbt-lastsync"
58 58
 
@@ -60,7 +60,9 @@ core__rsync__list(){
60 60
 
61 61
     config__get "_remote_dir" "remote_dir" "/data"
62 62
 
63
-    printf "%s^%s\n" "${_remote_dir}" "`date -j -r "${_file}" +"%Y%m%d%H%M"`"
63
+    _size=`du -hs "${ssbt_dir}/${_host}/"`
64
+
65
+    printf "%s^%s^%s\n" "${_remote_dir}" "`date -j -r "${_file}" +"%Y%m%d%H%M"`" "${_size}"
64 66
 }
65 67
 
66 68
 # Remove backup

+ 7
- 4
lib/core-rsynczfs View File

@@ -65,15 +65,18 @@ core__rsynczfs__pull(){
65 65
 # List local backups (youngest first)
66 66
 #
67 67
 core__rsynczfs__list(){
68
-    local _host="$1" _filesystem _snapshot _timestamp
68
+    local _host="$1" _filesystem _snapshot _timestamp _size
69 69
 
70 70
     _filesystem=`core__rsynczfs__getfs "${_host}"`
71 71
 
72
-    zfs list -Hp -t snapshot -o name -r "${_filesystem}" | sort -r | \
73
-    while read _snapshot; do
72
+    zfs list -Hp -t snapshot -o name,used -r "${_filesystem}" | sort -r | \
73
+    while read _line; do
74
+        _snapshot=`echo "${_line}" | cut -f1`
75
+        _size=`echo "${_line}" | cut -f2`
76
+
74 77
         _timestamp="${_snapshot##*@}"
75 78
 
76
-        printf "%s^%s\n" "${_snapshot}" "${_timestamp}"
79
+        printf "%s^%s^%s\n" "${_snapshot}" "${_timestamp}" "${_size}"
77 80
     done
78 81
 }
79 82
 

+ 3
- 2
lib/core-sftp View File

@@ -96,14 +96,15 @@ core__sftp__pull(){
96 96
 # List local backed up files (youngest first)
97 97
 #
98 98
 core__sftp__list(){
99
-    local _host="$1" _file _timestamp
99
+    local _host="$1" _file _timestamp _size
100 100
 
101 101
     ls -1r "${ssbt_dir}/${_host}" | grep -v ".ssbt." | grep -v ".sha256" 2>/dev/null | \
102 102
     while read _file; do
103 103
         _timestamp=${_file##*-}
104 104
         _timestamp=${_timestamp%%.*}
105
+        _size=`stat -f %z "${ssbt_dir}/${_host}/${_file}"`
105 106
 
106
-        printf "%s^%s\n" "${_file}" "${_timestamp}"
107
+        printf "%s^%s^%d\n" "${_file}" "${_timestamp}" "${_size}"
107 108
     done
108 109
 }
109 110
 

+ 14
- 0
lib/util View File

@@ -220,3 +220,17 @@ util__dateformat(){
220 220
         date -j "${_date}${_time}" "${_format}"
221 221
     fi
222 222
 }
223
+
224
+util__numberformat(){
225
+    local _size="$1"
226
+    local _units="B KiB MiB GiB TiB PiB"
227
+    local _unit
228
+
229
+    for X in ${_units}; do
230
+        _unit=$X
231
+        test ${_size%.*} -lt 1024 && break;
232
+        _size=`echo "${_size} / 1024" | bc -l`
233
+    done
234
+
235
+    printf "%.1f %s\n" ${_size} ${_unit}
236
+}

Loading…
Cancel
Save