WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Display backup file information - showbackup.sh  (Read 4214 times)

Offline ixbrian

  • Retired Admins
  • Sr. Member
  • *****
  • Posts: 436
Display backup file information - showbackup.sh
« on: August 08, 2010, 08: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.   

Code: [Select]
#!/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


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: Display backup file information - showbackup.sh
« Reply #1 on: February 11, 2013, 11:14:27 AM »
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.
Code: [Select]
#!/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

 
« Last Edit: February 11, 2013, 11:18:09 AM by Rich »

Offline ixbrian

  • Retired Admins
  • Sr. Member
  • *****
  • Posts: 436
Re: Display backup file information - showbackup.sh
« Reply #2 on: February 11, 2013, 10:58:49 PM »
Thanks for updating Rich.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: Display backup file information - showbackup.sh
« Reply #3 on: February 12, 2013, 08:57:34 AM »
Here is my attempt to make it compatible with protected backup:

Code: [Select]
--- 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
-
« Last Edit: November 10, 2013, 08:43:08 PM by tinypoodle »
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline mocore

  • Hero Member
  • *****
  • Posts: 633
  • ~.~
Re: Display backup file information - showbackup.sh
« Reply #4 on: November 10, 2013, 01:40:08 PM »
 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."
« Last Edit: November 17, 2013, 06:56:33 AM by mocore »

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: Display backup file information - showbackup.sh
« Reply #5 on: November 10, 2013, 08:44:40 PM »
Uhuh  :P
Quote
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.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline mocore

  • Hero Member
  • *****
  • Posts: 633
  • ~.~
Re: Display backup file information - showbackup.sh
« Reply #6 on: November 17, 2013, 06:55:41 AM »

doh !
Quote
Patches will be deleted after 90 days.
& thanks! i missed that ..

>Dead link removed.
 them dead links and inline code make forum surfing  RESTless