How to set up automated daily backups (non-Docker)?

In order to comply with the Mastodon Server Covenant, we want to setup daily backups for our non-Docker Mastodon instance (currently we have automatic weekly backups for the entire server). Post-installation steps - Mastodon documentation explains what needs backup but requires to know what you’re doing. :sweat_smile: Do you know about a step by step guide or… how have you solved this problem?

I wrote this tiny script called each day by the crontab of root, it keeps 7 days of backup :

TAR="$(which tar)"
GZIP="$(which gzip)"
AUJOURDHUI=$(date +%F)
cd /tmp
sudo -n -u postgres pg_dump mastodon_production > /tmp/dump_mastodon_$AUJOURDHUI.sql
mv /tmp/dump_mastodon_$AUJOURDHUI.sql $SAUVEGARDE/$AUJOURDHUI/dump.sql
cp /var/lib/redis/dump.rdb $SAUVEGARDE/$AUJOURDHUI
$TAR -vzcf $SAUVEGARDE/$AUJOURDHUI/SauvegardeMastodon_$AUJOURDHUI.tgz $SAUVEGARDE/$AUJOURDHUI/dump.* $MASTODON/.env.production && rm -f $SAUVEGARDE/$AUJOURDHUI/dump.*
find $SAUVEGARDE/* -type d -ctime +6 | xargs rm -rf
tree -hrcDup $SAUVEGARDE
df -ht ext4

Any suggestions for improvement are welcome!


I think to need three kind of backups at least which are postgres, redis, and .env.production. Optionally, need to icons, headers, and media attachments too.

This is my scripts :smile:

1 Like

Is there any way i can send backup to Google drive? I got unlimited account and it will save me some buck

@vibhigupta hmm…sorry, I don’t have the knowledge to work with google drive. :cry:
I backing up these datas as secondary backups to my home server with rsync over ssh.

1 Like