Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 31st, 2011  |  syntax: Bash  |  size: 0.91 KB  |  views: 169  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. dummy_s=
  4. mail_list="user@gmail.com"
  5.  
  6. a=$@
  7.  
  8. #Get interval
  9. int=`echo $a | awk '{ print $NF }'`
  10.  
  11. #Remove interval from arguments
  12. aa=`echo $a | sed '$s/ *\([^ ]* *\)$//'`
  13. #Get config name with fake interval
  14. config=`rsnapshot  -v $aa kjszdghm34w 2>&1 | awk '/ERROR/ {print $6}'`
  15.  
  16. #Get snapshot root
  17. sroot=`cat $config | awk '$1 ~ /snapshot_root/ {print $2}'`
  18. co=$sroot/control
  19. #touch "$co"
  20.  
  21. cleanup_old() {
  22.         $dummy_s mv "$sroot"/"$int".0 "$sroot"/"$int".0.failed
  23.         $dummy_s rm "$co"
  24. }
  25.  
  26. send_notification() {
  27. (echo ERROR: Control file exists. Previous backup has not completed; \
  28. ls -l $co) \
  29. | mailx -s "Rsnapshot has failed on `hostname`" $mail_list
  30. }
  31.  
  32. if [ -f "$co" ]; then
  33. echo ERROR: Control file exists. Previous backup has not completed
  34. send_notification
  35. cleanup_old
  36. fi
  37.  
  38. $dummy_s touch "$co"
  39. $dummy_s rsnapshot  $@
  40. $dummy_s rm "$co"; logger backup completed $config
clone this paste RAW Paste Data