[FR/EN] Script Backup for Mysql

Bonjour les Podmins,

J’ai trouvé sur le wiki diasporafondation un script pour effectuer un backup de son Pod. Souci quand je le lance j’ai une erreur “Unknown adapter mysql2”, j’en déduis qu’il ne prends pas en charge les installations avec Mysql.

Existe t’il donc une version pour Mysql ?

Merci à vous pour votre aide.

Scott
dicespora.net


Hello Podmins,

I found in the diasporafondation’s wiki a script to make a backup of my Pods but when i run it, i’ve an error “Unknown adapter mysql2” so i think mysql isn’t coded in this script.

So does exist a Mysql version of this script ?

Thanks all for your help.

Scott
dicespora.net

Hi there!
Well, if you read the description, it says “The presented version only supports PostgreSQL for now, but MySQL support could easily be added.” :slight_smile:

You can add it yourself by adding section in, something like this:

  mysql2)
    echo "Running MySQL dump..."
    TMP_FILE=$( mktemp )
    mysqldump -u $USERNAME -p $PASSWORD $DATABASE > $TMP_FILE
    status=$?
    if [ $status -ne 0 ]; then
      echo "Error running dump command: $status"
      exit $status
    fi
    gzip -n $TMP_FILE
    mv $TMP_FILE.gz $DUMP_FILE_NAME.sql.gz
    ;;

Test it of course, I don’t have MySQL.

Hello Alexander,

Thanks a lot for your answer, i’ll test your scripts right now !

I replace the Postgresql part by your script :

case $ADAPTER in
mysql)
echo “Running MySQL dump…”
TMP_FILE=$( mktemp )
mysqldump -u $USERNAME -p $PASSWORD $DATABASE > $TMP_FILE
status=$?
if [ $status -ne 0 ]; then
echo “Error running dump command: $status”
exit $status
fi
gzip -n $TMP_FILE
mv $TMP_FILE.gz $DUMP_FILE_NAME.sql.gz
;;
esac

Here the scripts logs :

[diaspora@dicespora:~/diaspora/script] master* ± ./backup.sh
Creating archive diaspora_dicespora.net_2020-02-20_10-24-58.tar…
tar: mysql2_diaspora_production_2020-02-20_10-24-58.sql.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
Error 2 running tar. Archive wasn’t created.
unlink: cannot unlink ‘mysql2_diaspora_production_2020-02-20_10-24-58.sql.gz’: No such file or directory

After some tiny correction (suppression 3 spaces in mysqldump line)

case $ADAPTER in
mysql2)
echo “Running MySQL dump…”
TMP_FILE=$( mktemp )
mysqldump -u$USERNAME -p$PASSWORD $DATABASE > $TMP_FILE
status=$?
if [ $status -ne 0 ]; then
echo “Error running dump command: $status”
exit $status
fi
gzip -n $TMP_FILE
mv $TMP_FILE.gz $DUMP_FILE_NAME.sql.gz
;;
esac

your script works !!!

Thanks a lot Alexander :slight_smile:

Glad it helped.

Be sure to keep an eye on backups because if something happens to your server and you won’t be able to restore from backup, you’ll lose not only pod data but also ability to use same addresses (user@domain) forever. It is important :slight_smile:

Hello Alexander,

Can you tell me more? What you’re telling me is disturbing.

you’ll lose not only pod data but also ability to use same addresses (user@domain) forever. It is important

In a nutshell: when you create an account you also create an encryption key which is used to verify your identity. It is stored in your server database. When you add contacts, the other servers take record of this key to identify you in the future.

If you lose your database and have no backup, you won’t be able to use same usernames because if you do, other servers will remember the previous identity with the old key and reject new one as counterfeit. You will have to use new usernames (or domain).

So having backups is really important, especially if you plan to host other people. Keep some of them off your server too.