Script Backup Incremental.

d
Autor: GhosTi
Visto en Blog of Sysadmins
#!/bin/sh
TAR=$(which tar)
TEE=$(which tee)
 
 
 
ARGS=2
 
if [ $# -ne $ARGS ]
 
then
echo “Usage: “$0” file dir”
echo ” file: backup file name”
echo ” dir: path to backup”
exit
fi
 
APP=$0 #app name
FILE=$1“_incremental.tgz” #backup file
FILE_FULL=$1“_full.tgz” #backup full
FILE_OLD=$FILE“~” #file backuped before remove
DIR=$2 #path
 
LOG_DIR=/var/log
LOG_FILE=$LOG_DIR“/”${APP##*\/}“.log” #remuevo de APP lo que este antes de la ultima /
 
TODAY=`date “+%Y-%m-%d %a”`
echo $TODAY” *** Backup incremental ***” | $TEE -a $LOG_FILE
 
if [ ! -d $DIR ]
then
echo “ERROR: path “$DIR” not exist” | $TEE -a $LOG_FILE
exit
fi
 
# Reviso si existe el backup full
if [ ! -f $FILE_FULL ];
then
echo “ERROR: full backup “$FILE_FULL” not exist!” | $TEE -a $LOG_FILE
exit
fi
 
#Realizo backup del backup
 
echo “Rotating files…” | $TEE $LOG_FILE
 
if [ -f $FILE ];
 
then
#cp -v $FILE $FILE_OLD | $TEE $LOG_FILE
rm -v $FILE | $TEE $LOG_FILE
fi
 
#Realizo el backup
DATE_FULL=“`date \”+%Y-%m-%d %H:%M\” -r “$FILE_FULL“`”
echo “Full backupe created: “$DATE_FULL | $TEE $LOG_FILE
 
echo “Making backup…” | $TEE $LOG_FILE
$TAR -chzf $FILE –newer-mtime=“$DATE_FULL” $DIR | $TEE -a $LOG_FILE
 
if [ $? == 0 ]
then
echo “Backup successfull!”
else
echo “ERROR: error making backup :-( “
fi

0 comentarios: