WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: filetool.sh bug in tc_3.8.4; SAFE backup fails if mydata.tgz does not yet exist  (Read 2944 times)

Offline redwolf

  • Newbie
  • *
  • Posts: 20
While trying to backup to a newly created tce2, I got an error stating "Error: Unable to rename mydata.tgz to mydatabk.tgz".  Strangely, subsequent attempts to backup via Control Panel tool revealed that the backup target had been changed to 'sdd1/tce2-b'.  Changing the backup device listed in /opt/.backup_device back to sdd1/tce2 and retrying ended with the same results..."Error: Unable to rename mydata.tgz to mydatabk.tgz", and /opt/.backup_device now listed sdd1/tce2-b.

After examining filetool.sh, I realized the reason for the failure...mydata.tgz did not exist yet...because this was a new TCE that I had just booted into for the first time...and filetool.sh does not check if mydata.tgz or mydata.tgz.bfe exist before trying to rename them to mydatabk.tgz or mydatabk.tgz.bfe, respectively.

The fact that filetool.sh dumps the standard error from the mv operation to /dev/nul makes it a little more cryptic and hard to figure out what the cause is as well.  Consider "mv: can't rename 'mydata.tgz': No such file or directory.", what get's dumped to /dev/null in this instance, vs. "Error: Unable to rename mydata.tgz to mydatabk.tgz", what is shown instead.

To make matters worse, anyone encountering this bug is then told to check /tmp/backup_status for clues, but since standard error was dumped to /dev/null instead of /tmp/backup_status, /tmp/backup_status does not exist!

I was able to fix this bug by testing for the existence of mydata.tgz or mydata.tgz.bfe before attempting to rename the file.  This allows the backup to be created and seems to have resolved the strange side-effect where the target backup device was getting -b appended to it.  I also dump standard error to /tmp/backup_status in the event that some actual problem prevents the mv operation from completing, one isn't left scratching their head.

The original code and the modified code follow.

Excerpt from original filetool.sh

Code: (bash) [Select]
if [ "$BACKUP" ] ; then
  sed -i /^$/d /opt/.filetool.lst
  if [ "$SAFE" ]; then
    sudo mv -f $MOUNTPOINT/"$FULLPATH"/${MYDATA}.tgz $MOUNTPOINT/"$FULLPATH"/${MYDATA}bk.tgz 2>/dev/null || sudo mv -f $MOUNTPOINT/"$FULLPATH"/${MYDATA}.tgz.bfe $MOUNTPOINT/"$FULLPATH"/${MYDATA}bk.tgz.bfe 2>/dev/null
    if [ "$?" != 0 ]; then
      echo "Error: Unable to rename ${MYDATA}.tgz to ${MYDATA}bk.tgz"
      exit 2
    fi
  fi
                                                                   

Excerpt from modified filetool.sh with Fix

Code: (bash) [Select]
if [ "$BACKUP" ] ; then
  sed -i /^$/d /opt/.filetool.lst
  if [ "$SAFE" ]; then
    if [ -r $MOUNTPOINT/"$FULLPATH"/${MYDATA}.tgz.bfe -o -r $MOUNTPOINT/"$FULLPATH"/${MYDATA}.tgz ]; then
      echo -n "${BLUE}Copying existing backup to ${GREEN}$MOUNTPOINT/"$FULLPATH"/${MYDATA}bk.[tgz|tgz.bfe]${NORMAL} .. "
      sudo mv -f $MOUNTPOINT/"$FULLPATH"/${MYDATA}.tgz $MOUNTPOINT/"$FULLPATH"/${MYDATA}bk.tgz 2>/tmp/backup_status || sudo mv -f $MOUNTPOINT/"$FULLPATH"/${MYDATA}.tgz.bfe $MOUNTPOINT/"$FULLPATH"/${MYDATA}bk.tgz.bfe 2>/tmp/backup_status
      echo "${GREEN}Done."
      if [ "$?" != 0 ]; then
        echo "Error: Unable to rename ${MYDATA}.tgz to ${MYDATA}bk.tgz"
        exit 2
      fi
    else
      echo "Neither ${MYDATA}.tgz nor ${MYDATA}.tgz.bfe exist.  Proceeding with creation of initial backup ..."
    fi
  fi

edited title to more accurately reflect suggestion.
« Last Edit: September 27, 2011, 12:15:45 PM by roberts »

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Suggested changes accepted. Thanks!
10+ Years Contributing to Linux Open Source Projects.