3

I wrote this backup script. I run rsync, tar and a dump of mysql. I'd like to add some features like email alert or some kind of statistic.

Here is the script:

#!/bin/sh

DATE=`date +%D-%T`
ORIGIN=/home/share/
DEST=/media/BACKUP/mercurio/
LOGFILE=log.txt
echo "=====Starting backup on $DATE =====" >> $LOGFILE
echo "==Start rsync" >> $LOGFILE 
rsync -arHu --delete --stats $ORIGIN $DEST/share >> $LOGFILE
wait
if [ $? -eq 0 ]
then
        echo "==rsync ok"  >> $LOGFILE
else
        echo "==rsync ko"   >> $LOGFILE
fi

echo "==Sart TAR" >> $LOGFILE
tar -czf $DEST`date +%y%m%d-%T`.tar.gz $ORIGIN
wait
if [ $? -eq 0 ]
then
        echo "==tar ok" >> $LOGFILE
else
        echo "==tar ko" >> $LOGFILE
fi
echo "==Start DUMP" >> $LOGFILE
mysqldump -u root -ptoor --all-databases > ${DEST}databases/`date +%Y%m%d-%k:%M`.sql
wait
if [$? -eq 0 ]
then
        echo "==dump ok" >> $LOGFILE
else 
        echo "==dump ko" >> $LOGFILE
fi
echo "=====End Bakcup=====" >> $LOGFILE
8
  • 1
    Your question is a bit vague. What kind of email alert? Statistics for what? (And what have you tried for either?)
    – Mat
    Commented Feb 3, 2012 at 12:09
  • sorry i don't have a precise idea, i think some guru here can give me some advice like "you need an email alert if backup fails" or "add auto-delete file older than 30days"
    – Ignazio
    Commented Feb 3, 2012 at 12:20
  • 1
    So you're asking for general best practices for backups, retention periods, and monitoring? That's a bit broad to say the least. We don't even know what kind of data you're backing up. You also need to take potential legal requirements into consideration. Practical limitations with how much storage you have available...
    – Mat
    Commented Feb 3, 2012 at 12:22
  • you're right...this is a too generic question :( The files aren't vital for my business...i copy on this server only the file that i want to share with my colleagues. Server is configured as lamp for a simple wikimedia installation so i want to backup also mysql.
    – Ignazio
    Commented Feb 3, 2012 at 12:31
  • You should also redirect stderr to you log files, like 2>>. >> is like 1>> and redirects stdout only. Also use --log-error=filename.log for mysqldump. Commented Feb 3, 2012 at 14:21

0

Browse other questions tagged .