Skip to main content


My #GoToSocial backup procedure:

This runs as a cron job every day at an off-peak hour. Do bear in mind that both the sqlite backup, which takes place while GTS is running and therefore must handle locks, and xz, take up a lot of CPU power.

#!/bin/bash
umask 027
now0="$(date +'%F %T')"
printf "%s: Starting backup.\n" "$now0"
cd /home/gts/gts || { printf "Impossible to backup. Cannot access directory.\n"; exit; }
mv --backup=numbered instance.back.tar.xz db-backups
printf "Backing up database.\n"
sqlite3 sqlite.db ".backup 'sqlite.db.back'"
printf "Preparing file list.\n"
echo sqlite.db.back > file.list
echo config.yaml >> file.list
echo db-backup.sh >> file.list
echo file.list >> file.list
./gotosocial --config-path config.yaml admin media list-attachments --local-only >> file.list
./gotosocial --config-path config.yaml admin media list-emojis --local-only >> file.list
printf "Tarring up instance data.\n"
tar -cf instance.back.tar -T file.list
printf "Removing auxiliary files.\n"
rm sqlite.db.back file.list
xz -T3 -e --best instance.back.tar
now="$(date +'%F %T')"
printf "%s: Finished backing up.\n" "$now"
in reply to modulux

One thing I want to do to improve this, is using ts to timestamp the output on the log. I run this on a cron job and redirect it to a log file so that I can see if any command has failed or any dodgy things has happened.