MastodonHelp/web/clitools/maintain/backup.bash
2022-12-03 14:47:28 +01:00

49 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
# disabilitato invio mail perché ormai son troppo grosse per smtp di indivia, scarico i nuovi backup quotidianamente con rsync
# riabilitato dopo pulizia db
mailcfgfp="../../conf/mail.conf"
mastcfgfp="../../conf/mustard.ini"
basedir=`dirname "$0"`
cd "$basedir"
function isok {
if [ $? -eq 0 ]; then
echo "ok :-)"
else
echo "qualcosa è andato storto, muoio :-("
exit $?
fi
}
date=`date`
mailmta=`cat "$mailcfgfp"|grep -P '^mta='|sed -e 's/^mta=//' -e 's/^"//' -e 's/"$//'`
mailfrom=`cat "$mailcfgfp"|grep -P '^from='|sed -e 's/^from=//' -e 's/^"//' -e 's/"$//'`
mailto=`cat "$mailcfgfp"|grep -P '^to='|sed -e 's/^to=//' -e 's/^"//' -e 's/"$//'`
if [ "$1" != "testmail" ]; then
dbname=`cat "$mastcfgfp"|grep -P '^db_name='|sed -e 's/^db_name=//' -e 's/^"//' -e 's/"$//'`
dbuser=`cat "$mastcfgfp"|grep -P '^db_admin_name='|sed -e 's/^db_admin_name=//' -e 's/^"//' -e 's/"$//'`
dbpass=`cat "$mastcfgfp"|grep -P '^db_admin_password='|sed -e 's/^db_admin_password=//' -e 's/^"//' -e 's/"$//'`
ofp=backups/"$dbname"_backup-`date +%Y-%m-%d--%H.%M.%S`.sql
echo -n "Eseguo il dump... "
mysqldump -u "$dbuser" -p"$dbpass" "$dbname" -r "$ofp"
isok
else
ofp=backups/test.data
[ -e "${ofp}.xz" ] && rm "${ofp}.xz"
echo -n "Creo il finto file di dump da allegare per test... "
dd if=/dev/urandom of="$ofp" bs=1024 count=1024 &>/dev/null
isok
fi
echo -n "Comprimo il dump... "
xz -9 "$ofp"
isok
echo -n "Invio il dump... "
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"
isok
[ "$1" == "testmail" -a -e "${ofp}.xz" ] && rm "${ofp}.xz"
exit 0