WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Adding "Dry Run Backup" mode to filetool.sh  (Read 3542 times)

Offline ixbrian

  • Retired Admins
  • Sr. Member
  • *****
  • Posts: 436
Adding "Dry Run Backup" mode to filetool.sh
« on: September 11, 2010, 11:08:27 PM »
I have made some modifications to filetool.sh that add an option for a "Dry Run Backup".  This displays on the screen what files would be included in your backup, each file's size, the total size of files uncompressed, and the size the compressed backup would be (without actually writing the backup anywhere).   I think this will be useful if you are changing .filetool.lst or .xfiletool.lst as you can see what files would be included in your backup without actually doing a backup.   It would also be useful to determine what the largest files in your backup would be so that you can reduce the backup size.  

This dry run backup doesn't actually write the backup anywhere so it doesn't require any free space on your hard drive.  

Here is the output produced:  

Code: [Select]
$ filetool.sh -d
Performing dry run backup (backup will not actually take place).   Please wait.

  0.00 MB  /etc/motd
  0.00 MB  /home/tc/.profile
  0.00 MB  /home/tc/.ashrc
  0.00 MB  /home/tc/.Xdefaults
  0.00 MB  /home/tc/.xsession
  0.00 MB  /home/tc/.wbar
  0.00 MB  /home/tc/.setbackground
  0.00 MB  /home/tc/.ash_history
  9.54 MB  /home/tc/testfile
  8.17 MB  /home/tc/testfile2
  0.00 MB  /home/tc/.config/gtk-2.0/gtkfilechooser.ini
  0.00 MB  /home/tc/.fltk/fltk.org/filechooser.prefs
  0.00 MB  /opt/.xfiletool.lst
  0.00 MB  /opt/.filetool.lst
  0.00 MB  /opt/tcemirror
  0.00 MB  /opt/shutdown.sh
  0.00 MB  /opt/bootlocal.sh
  0.00 MB  /usr/local/share/man/man1/curl-config.1

Total backup size (uncompressed):   17.71 MB (18570462 bytes)
Total backup size (compressed)  :    8.16 MB (8554445 bytes)


Here is the unified diff from the 3.1rc4 filetool.sh:

Code: [Select]
--- filetool.sh
+++ /usr/bin/filetool.sh
@@ -17,7 +17,6 @@
   echo "-p prompt"
   echo "-r restore"
   echo "-s safe backup mode"
-  echo "-d dry run backup"
   echo -n "Press enter to continue:" ; read ans
   exit 1
 }
@@ -50,43 +49,23 @@
 }
 
 # Main  --
-unset BACKUP PROMPT RESTORE SAFE DRYRUN
+unset BACKUP PROMPT RESTORE SAFE
 
 [ -z $1 ] && abort
 if grep -q "safebackup" /proc/cmdline; then SAFE=TRUE; fi
-while getopts bprsd OPTION
+while getopts bprs OPTION
 do
   case ${OPTION} in
    b) BACKUP=TRUE ;;
    p) PROMPT=TRUE ;;
    r) RESTORE=TRUE ;;
    s) SAFE=TRUE ;;
-   d) DRYRUN=TRUE ;;
    *) abort ;;
   esac
 done
 [ "$BACKUP" ] && [ "$RESTORE" ] && abort
 shift `busybox expr $OPTIND - 1`
 # TARGET device is now $1
-
-if [ $DRYRUN ]; then
-  echo "${BLUE}Performing dry run backup (backup will not actually take place).   Please wait.${NORMAL}"; echo
-  totalcompressedsize=`sudo busybox tar -C / -T /opt/.filetool.lst -X /opt/.xfiletool.lst -cvzf - 2>/tmp/backup_dryrun_list | busybox wc -c`
-  for entry in `cat /tmp/backup_dryrun_list`; do
-    if [ -f "/${entry}" ]; then
-      size=`sudo busybox ls -al "/${entry}" | busybox awk '{print $5}'`
-      totalsize=$(($totalsize + $size))
-      sizemb=`busybox dc $size 1024 / 1024 / p`
-      printf "%6.2f MB  /%s\n" $sizemb $entry
-    fi
-  done
-  rm /tmp/backup_dryrun_list
-  totalsizemb=`busybox dc $totalsize 1024 / 1024 / p`
-  totalcompressedsizemb=`busybox dc $totalcompressedsize 1024 / 1024 / p`
-  printf "\nTotal backup size (uncompressed):  %6.2f MB (%d bytes)\n" $totalsizemb $totalsize
-  printf "Total backup size (compressed)  :  %6.2f MB (%d bytes)\n\n" $totalcompressedsizemb $totalcompressedsize
-  exit 0
-fi
 
 #Get the TARGET name from argument 1 or /opt/.backup_device
 if [ -z $1 ]; then

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: Adding "Dry Run Backup" mode to filetool.sh
« Reply #1 on: September 17, 2010, 07:50:35 AM »
Accepted into base.
10+ Years Contributing to Linux Open Source Projects.