Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: ixbrian on August 08, 2010, 05:01:51 PM
-
Below is a script that will display a listing of the files in your backup in descending order based on file size. For each file in your backup, it will show the size and what the percentage of space that the file takes verses the entire backup file size (I found on my system that there is one file in my backup that takes up 86% of the backup) At the end of the output, there is a summary that shows your backup file size both compressed and uncompressed.
#!/bin/sh
# showbackup.sh - Copyright 2010 Brian Smith
# Licensed under GPLv2 License
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
. /etc/init.d/tc-functions
if ! [ -r /opt/.backup_device ]; then
echo "error: backup device not found"
exit 2
fi
##### Following 5 lines from filetool.sh by Robert Shingledecker #####
TARGET="$(cat /opt/.backup_device 2>/dev/null)"
TARGET="${TARGET#/dev/}"
DEVICE="${TARGET%%/*}"
FULLPATH="${TARGET#$DEVICE/}"
find_mountpoint $DEVICE
######################################################################
totalsize=`busybox ls -al "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{print $5}'`
totalsize_uncompressed=`busybox tar -tvzf "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{ total += $3 } END { print total }'`
IFS="
"
for entry in `busybox tar -tvzf "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{$2=""; $5=""; print}' | busybox sort -nk 2`; do
perm=`echo $entry | busybox awk '{print $1}`
size=`echo $entry | busybox awk '{print $2}`
date=`echo $entry | busybox awk '{print $3}`
path=`echo $entry | busybox awk '{$1=""; $2=""; $3=""; print}`
percent=`busybox dc $size $totalsize_uncompressed / 100 \* p`
sizemb=`busybox dc $size 1024 / 1024 / p`
if [ ${perm:0:1} = "d" ]; then
printf "---Directory--- %-9s %s\n" $date $path
else
printf "%4.1f%% %5.2f MB %-9s %s\n" $percent $sizemb $date $path
fi
done
totalsizemb=`busybox dc $totalsize 1024 / 1024 / p`
totalsize_uncompressed_mb=`busybox dc $totalsize_uncompressed 1024 / 1024 / p`
printf "\nTotal backup size (uncompressed): %6.2f MB (%d bytes)\n" $totalsize_uncompressed_mb $totalsize_uncompressed
printf "Total backup size (compressed) : %6.2f MB (%d bytes)\n\n" $totalsizemb $totalsize
-
Hi ixbrian
I wanted to include a link to this script as part of an answer in another thread. I found it doesn't work with
TC4.1 because backup_device was moved from /opt to /etc/sysconfig. I hope you don't mind, I made two
small changes to make it compatible for both cases. Signed comments included to show what I did.
#!/bin/sh
# showbackup.sh - Copyright 2010 Brian Smith
# Licensed under GPLv2 License
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
. /etc/init.d/tc-functions
if ! [ -r /opt/.backup_device ]; then
if ! [ -r /etc/sysconfig/backup_device ]; then # Added second if statement, Rich
echo "error: backup device not found"
exit 2
fi
fi
##### Following 5 lines from filetool.sh by Robert Shingledecker #####
# Added || clause in the following line, Rich
TARGET="$(cat /opt/.backup_device 2>/dev/null)" || TARGET="$(cat /etc/sysconfig/backup_device 2>/dev/null)"
TARGET="${TARGET#/dev/}"
DEVICE="${TARGET%%/*}"
FULLPATH="${TARGET#$DEVICE/}"
find_mountpoint $DEVICE
######################################################################
totalsize=`busybox ls -al "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{print $5}'`
totalsize_uncompressed=`busybox tar -tvzf "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{ total += $3 } END { print total }'`
IFS="
"
for entry in `busybox tar -tvzf "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{$2=""; $5=""; print}' | busybox sort -nk 2`; do
perm=`echo $entry | busybox awk '{print $1}`
size=`echo $entry | busybox awk '{print $2}`
date=`echo $entry | busybox awk '{print $3}`
path=`echo $entry | busybox awk '{$1=""; $2=""; $3=""; print}`
percent=`busybox dc $size $totalsize_uncompressed / 100 \* p`
sizemb=`busybox dc $size 1024 / 1024 / p`
if [ ${perm:0:1} = "d" ]; then
printf "---Directory--- %-9s %s\n" $date $path
else
printf "%4.1f%% %5.2f MB %-9s %s\n" $percent $sizemb $date $path
fi
done
totalsizemb=`busybox dc $totalsize 1024 / 1024 / p`
totalsize_uncompressed_mb=`busybox dc $totalsize_uncompressed 1024 / 1024 / p`
printf "\nTotal backup size (uncompressed): %6.2f MB (%d bytes)\n" $totalsize_uncompressed_mb $totalsize_uncompressed
printf "Total backup size (compressed) : %6.2f MB (%d bytes)\n\n" $totalsizemb $totalsize
-
Thanks for updating Rich.
-
Here is my attempt to make it compatible with protected backup:
--- showbackup.sh Tue Feb 12 15:49:26 2013
+++ showbackupnoprotect.sh Tue Feb 12 15:50:22 2013
@@ -25,11 +25,6 @@
find_mountpoint $DEVICE
######################################################################
-if [ -f "$MOUNTPOINT/"$FULLPATH"/mydata.tgz.bfe" ] # Added if statement for protected backup, tinypoodle
- then echo 'Please enter backup protect password enclosed by double quotation marks'
- bcrypt -r "$MOUNTPOINT/"$FULLPATH"/mydata.tgz.bfe"
-fi
-
totalsize=`busybox ls -al "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{print $5}'`
totalsize_uncompressed=`busybox tar -tvzf "$MOUNTPOINT/"$FULLPATH"/mydata.tgz" | busybox awk '{ total += $3 } END { print total }'`
@@ -55,8 +50,3 @@
totalsize_uncompressed_mb=`busybox dc $totalsize_uncompressed 1024 / 1024 / p`
printf "\nTotal backup size (uncompressed): %6.2f MB (%d bytes)\n" $totalsize_uncompressed_mb $totalsize_uncompressed
printf "Total backup size (compressed) : %6.2f MB (%d bytes)\n\n" $totalsizemb $totalsize
-
-if [ -f "$MOUNTPOINT/"$FULLPATH"/mydata.tgz.bfe" ] # Remove decrypted backup if protected backup exists, tinypoodle
- then rm "$MOUNTPOINT/"$FULLPATH"/mydata.tgz"
-fi
-
-
server monkey seems to have lost or killed this file link
patches.tinycorelinux.net/uploaded/ showbackupprotect.diff
shows
"Not Found - The requested URL was not found on this server."
-
Uhuh :P
Patches will be deleted after 90 days.
Be assured though that the diff referenced by the now dead link was of exact same content as what is still available inline, just in the more practical form of a downloadable file.
Dead link removed.
-
doh ! Patches will be deleted after 90 days.
& thanks! i missed that ..
>Dead link removed.
them dead links and inline code make forum surfing RESTless