Help needed to backup files.

Hi guys ,

I m writing a script in linux which will backup a particular folder and its content to a different location.

this script needs to be run every weekend.

But my problem is how would i apply logic such that the previous backup folder is only deleted if and only if the current backup is successful.
my code
PHP:
cp /OVS/running_pool/$VM_Guest/*.* /mnt/ntserver/$VM_Guest/

if [ "$?" -ne "0" ]; then
  echo "Problem in copying the data"
fi
 
pinga123 said:
But my problem is how would i apply logic such that the previous backup folder is only deleted if and only if the current backup is successful.

confused with your sentence :S ... please clearly mention your logic again
 
this should do it

Code:
#!/bin/sh
BACKUP_DATE=`date +"%Y%m%d"`
PREV_BACKUP_DATE=`date +"%Y%m%d" -d last-week`
export BACKUP_DATE
export PREV_BACKUP_DATE
cp -R /root /tmp/tmp_weekly_backup/root_$BACKUP_DATE
if [ "$?" -ne "0" ]; then
  echo "Problem in copying the data"
else
  if [ -d /tmp/tmp_weekly_backup/root_$PREV_BACKUP_DATE ]; then
    echo "Found last week backup"
    rm -rf /tmp/tmp_weekly_backup/root_$PREV_BACKUP_DATE
    if [ "$?" -ne "0" ]; then
      echo "Problem in removing last week backup"
    fi
  else
    echo "No last week backup found"
  fi
fi
 
Back
Top