backup.bash 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # disabled mail send by default because mails got too big for indivia's smtp
  3. if [ "$1" == "help" -o "$1" == "-h" -o "$1" == "--help" ]; then
  4. echo "backup.bash [mail|testmail|help/--help/-h]"
  5. exit 0
  6. fi
  7. mailcfgfp="../../conf/mail.conf"
  8. mastcfgfp="../../conf/mustard.ini"
  9. basedir=`dirname "$0"`
  10. cd "$basedir"
  11. function isok {
  12. if [ $? -eq 0 ]; then
  13. echo "ok :-)"
  14. else
  15. echo "qualcosa è andato storto, muoio :-("
  16. exit $?
  17. fi
  18. }
  19. date=`date`
  20. mailmta=`cat "$mailcfgfp"|grep -P '^mta='|sed -e 's/^mta=//' -e 's/^"//' -e 's/"$//'`
  21. mailfrom=`cat "$mailcfgfp"|grep -P '^from='|sed -e 's/^from=//' -e 's/^"//' -e 's/"$//'`
  22. mailto=`cat "$mailcfgfp"|grep -P '^to='|sed -e 's/^to=//' -e 's/^"//' -e 's/"$//'`
  23. if [ "$1" != "testmail" ]; then
  24. dbname=`cat "$mastcfgfp"|grep -P '^db_name='|sed -e 's/^db_name=//' -e 's/^"//' -e 's/"$//'`
  25. dbuser=`cat "$mastcfgfp"|grep -P '^db_admin_name='|sed -e 's/^db_admin_name=//' -e 's/^"//' -e 's/"$//'`
  26. dbpass=`cat "$mastcfgfp"|grep -P '^db_admin_password='|sed -e 's/^db_admin_password=//' -e 's/^"//' -e 's/"$//'`
  27. ofp=backups/"$dbname"_backup-`date +%Y-%m-%d--%H.%M.%S`.sql
  28. echo -n "Eseguo il dump... "
  29. mysqldump -u "$dbuser" -p"$dbpass" "$dbname" -r "$ofp"
  30. isok
  31. else
  32. ofp=backups/test.data
  33. [ -e "${ofp}.xz" ] && rm "${ofp}.xz"
  34. echo -n "Creo il finto file di dump da allegare per test... "
  35. dd if=/dev/urandom of="$ofp" bs=1024 count=1024 &>/dev/null
  36. isok
  37. fi
  38. echo -n "Comprimo il dump... "
  39. xz -9 "$ofp"
  40. isok
  41. if [ "$1" == "mail" -o "$1" == "testmail" ]; then
  42. echo -n "Invio il dump... "
  43. echo "Ecco il backup del database di mastodon.help di $date." | s-nail -s "Backup del database di mastodon.help di $date" -a "${ofp}.xz" -S v15-compat -S from="$mailfrom" -S smtp-use-starttls -S mta="$mailmta" "$mailto"
  44. isok
  45. [ "$1" == "testmail" -a -e "${ofp}.xz" ] && rm "${ofp}.xz"
  46. fi
  47. exit 0