Advertisement
Biduleohm

Config Backup

Sep 3rd, 2015
4,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.37 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ### Parameters ###
  4. logfile="/tmp/config_backup_error.tmp"
  5. tarfile="/tmp/config_backup.tar"
  6. filename="$(date "+FreeNAS_Config_%Y-%m-%d_%H-%M-%S")"
  7. email="your_email@gmail.com"
  8. subject="Config Backup for FreeNAS"
  9.  
  10. if [ "$(sqlite3 /data/freenas-v1.db "pragma integrity_check;")" == "ok" ]
  11. then
  12. ### Send config backup ###
  13.     cp /data/freenas-v1.db "/tmp/${filename}.db"
  14.     md5 "/tmp/${filename}.db" > /tmp/config_backup.md5
  15.     sha256 "/tmp/${filename}.db" > /tmp/config_backup.sha256
  16.     cd "/tmp/"; tar -cf "${tarfile}" "./${filename}.db" ./config_backup.md5 ./config_backup.sha256; cd -
  17.     uuencode "${tarfile}" "${filename}.tar" | mail -s "${subject}" "${email}"
  18.     rm "/tmp/${filename}.db"
  19.     rm /tmp/config_backup.md5
  20.     rm /tmp/config_backup.sha256
  21.     rm "${tarfile}"
  22. else
  23. ### Send error message ###
  24.     (
  25.         echo "To: ${email}"
  26.         echo "Subject: ${subject}"
  27.         echo "Content-Type: text/html"
  28.         echo "MIME-Version: 1.0"
  29.         echo -e "\r\n"
  30.         echo "<pre style=\"font-size:14px\">"
  31.         echo ""
  32.         echo "Automatic backup of FreeNAS config failed."
  33.         echo ""
  34.         echo "The config file is corrupted!"
  35.         echo ""
  36.         echo "You should correct this problem as soon as possible."
  37.         echo ""
  38.         echo "</pre>"
  39.     ) >> "${logfile}"
  40.     sendmail -t < "${logfile}"
  41.     rm "${logfile}"
  42. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement