Script Full Backup

d
Autor: GhosTi
Visto en Blog of Sysadmins
#!/bin/bash
 
 
 
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“_full.tgz” #backup file
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 full *** “ | $TEE -a $LOG_FILE
 
if [ ! -d $DIR ]
then
echo “ERROR: path “$DIR” not exist” | $TEE -a $LOG_FILE
exit
fi
 
#Realizo backup del backup
echo “Rotating files…” | $TEE -a $LOG_FILE
 
if [ -f $FILE ];
then
#cp -v $FILE $FILE_OLD | $TEE -a $LOG_FILE
rm -v $FILE | $TEE -a $LOG_FILE
fi
 
echo “Making backup…” | $TEE -a $LOG_FILE
#Realizo el backup
$TAR -chzf $FILE $DIR | $TEE -a $LOG_FILE
 
if [ $? == 0 ]
then
echo “Backup successfull!”
else
echo “ERROR: error making backup :-( “
fi

0 comentarios: