@@ -26,7 +26,33 @@ if is_upgrade && egrep '^3\.([6-9]|1[012])\.' "$PREFIX/UPGRADED_FROM.txt" >/dev/
26
26
mkdir -p " $BACKUP_DIR "
27
27
# Try to check if free space on $BACKUP_DIR drive is not less than $PREFIX/state/pg/data contains
28
28
if command -v df > /dev/null && command -v du > /dev/null && command -v awk > /dev/null; then
29
- # we have enough commands to test it
29
+ # We have enough commands to test it.
30
+ # Explanation of arguments:
31
+ # `df`
32
+ # `-P` - use POSIX output format (free space in 4th column),
33
+ # `-BM` - print output in Megabytes
34
+ # `awk`
35
+ # `FNR==2` - take record (line) number two (first line in `df` output is table header)
36
+ # `gsub(...)` - remove non-numbers from 4th column
37
+ # `print $4` - well, print 4th column
38
+ # `du`
39
+ # `-s` - print only summary - i.e. only one line with total size of all
40
+ # files in direcrory passed as argument - unlike in normal case when it
41
+ # prints disk usage by each nested directory, recursively
42
+ # `-BM` - print output in Megabytes
43
+ #
44
+ # Example of `df -PBM .` output on my machine:
45
+ # ```
46
+ # Filesystem 1048576-blocks Used Available Capacity Mounted on
47
+ # /dev/sda1 246599M 210974M 24564M 90% /
48
+ # ```
49
+ # and awk would extract "24564" number from it
50
+ # Example of `du -sBM .` output on my machine:
51
+ # ```
52
+ # 172831M .
53
+ # ```
54
+ # and awk would extract "172831" number from it
55
+ #
30
56
megabytes_free=" $( df -PBM $BACKUP_DIR | awk ' FNR==2{gsub(/[^0-9]/,"",$4);print $4}' ) "
31
57
megabytes_need=" $( du -sBM $PREFIX /state/pg/data | awk ' {gsub(/[^0-9]/,"",$1);print $1}' ) "
32
58
if [ " $megabytes_free " -le " $megabytes_need " ]; then
@@ -120,7 +146,7 @@ if is_upgrade && egrep '^3\.([6-9]|1[01])\.' "$PREFIX/UPGRADED_FROM.txt" >/dev/n
120
146
else
121
147
# Copy failed, so remove partially-copied data and abort
122
148
rm -rf " $BACKUP_DIR /data"
123
- cf_console echo " Creating of backup failed"
149
+ cf_console echo " Backup creation failed"
124
150
cf_console echo " Please fix it before upgrading or disable upgrade by removing/renaming $PREFIX /state/pg/data prior to upgrade."
125
151
exit 1
126
152
fi
0 commit comments