Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ### Parameters ###
- logfile="/tmp/config_backup_error.tmp"
- tarfile="/tmp/config_backup.tar"
- filename="$(date "+FreeNAS_Config_%Y-%m-%d_%H-%M-%S")"
- email="your_email@gmail.com"
- subject="Config Backup for FreeNAS"
- if [ "$(sqlite3 /data/freenas-v1.db "pragma integrity_check;")" == "ok" ]
- then
- ### Send config backup ###
- cp /data/freenas-v1.db "/tmp/${filename}.db"
- md5 "/tmp/${filename}.db" > /tmp/config_backup.md5
- sha256 "/tmp/${filename}.db" > /tmp/config_backup.sha256
- cd "/tmp/"; tar -cf "${tarfile}" "./${filename}.db" ./config_backup.md5 ./config_backup.sha256; cd -
- uuencode "${tarfile}" "${filename}.tar" | mail -s "${subject}" "${email}"
- rm "/tmp/${filename}.db"
- rm /tmp/config_backup.md5
- rm /tmp/config_backup.sha256
- rm "${tarfile}"
- else
- ### Send error message ###
- (
- echo "To: ${email}"
- echo "Subject: ${subject}"
- echo "Content-Type: text/html"
- echo "MIME-Version: 1.0"
- echo -e "\r\n"
- echo "<pre style=\"font-size:14px\">"
- echo ""
- echo "Automatic backup of FreeNAS config failed."
- echo ""
- echo "The config file is corrupted!"
- echo ""
- echo "You should correct this problem as soon as possible."
- echo ""
- echo "</pre>"
- ) >> "${logfile}"
- sendmail -t < "${logfile}"
- rm "${logfile}"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement