From Social Iguana, 3 Weeks ago, written in Bash.
  1. # cat /root/bin/LocalBackup.sh
  2. echo "Starting backup at `date`" >> /root/backup.log
  3.  
  4.  
  5. BASEDIR=/mnt/bck
  6.  
  7. OSDIR=$BASEDIR/os
  8. DATADIR=$BASEDIR/data
  9. MYSQLDIR=$BASEDIR/mysql
  10.  
  11. DAYOFWEEK=$(date +"%u")
  12.  
  13. if [ ! -d "$OSDIR" ]; then
  14.         mkdir $OSDIR
  15. fi
  16.  
  17. if [ ! -d "$DATADIR" ]; then
  18.         mkdir $DATADIR
  19. fi
  20.  
  21. if [ ! -d "$DATADIR/$DAYOFWEEK" ]; then
  22.         mkdir $DATADIR/$DAYOFWEEK
  23. fi
  24.  
  25.  
  26. if [ ! -d "$MYSQLDIR" ]; then
  27.         mkdir $MYSQLDIR
  28. fi
  29.  
  30. if [ ! -d "$MYSQLDIR/$DAYOFWEEK" ]; then
  31.         mkdir $MYSQLDIR/$DAYOFWEEK
  32. fi
  33.  
  34. if [ "$DAYOFWEEK" == 6 ]; then
  35.         echo "starting weekly backup"
  36.         rm -f /root/data.snar
  37.         echo "          Starting OS Backup at `date`" >> /root/backup.log
  38.         tar -cvf $OSDIR/os._tar_._gz_ --gzip /etc /bin /root/ /boot /home /opt  /sbin /usr /var
  39.         echo "          Completing OS Backup at `date`" >> /root/backup.log
  40. fi
  41.  
  42. if [ ! -f "$OSDIR/os._tar_._gz_" ]; then
  43.         echo "          OS Backup is missing.   Recreate it started  at `date`" >> /root/backup.log
  44.         tar -cf $OSDIR/os._tar_._gz_ --gzip /etc /bin /root/ /boot /home /opt  /sbin /usr /var
  45.         echo "          Completing OS Backup at `date`" >> /root/backup.log
  46. fi
  47.  
  48. echo "          Starting Data Backup at `date`" >> /root/backup.log
  49. tar -cf $DATADIR/$DAYOFWEEK/data._tar_._gz_ --listed-incremental=/root/data.snar --gzip  /data
  50. echo "          Completing Backup at `date`" >> /root/backup.log
  51.  
  52. echo "          Starting MySQL Backup at `date`" >> /root/backup.log
  53. cp -r /var/mysql/ $MYSQLDIR/$DAYOFWEEK/.
  54. echo "          Completing MySQL Backup at `date`" >> /root/backup.log
  55. echo "Backup completed at `date`" >> /root/backup.log
  56. echo ""  >> /root/backup.log
captcha