Created
November 21, 2022 08:19
-
-
Save freiheit/cac754d6fbe5b6e3bc54c1b2743f6a83 to your computer and use it in GitHub Desktop.
Backup key info from a mastodon account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Requires: | |
# - bash | |
# - mmv: usually in an "mmv" package | |
# - madonctl: https://github.com/McKael/madonctl | |
# - One of hardlink, xz, gzip or bzip2, depending on COMPRESSEXT | |
# Set up madonctl per instructions, so that it's linked to your instance and account. | |
# Settings | |
PATH=$PATH:/root/bin | |
DIR=/opt/mastodon-backup/ | |
KEEP=45 | |
SLEEP=30s | |
COMPRESSEXT="" # '', '.xz', '.gz', '.bz2' | |
FIELDS="Account ID:|User ID:|URL:|^-" | |
cd $DIR | |
# If rotated this far, remove oldest backup: | |
rm -vf *.${KEEP}${COMPRESSEXT} | |
# Rotate backups, so that *.10 becomes *.11, *.0 becomes *.1, etc | |
for i in $(seq ${KEEP} -1 1); do | |
j=$((${i}-1)) | |
mmv "*.${j}${COMPRESSEXT}" "#1.${i}${COMPRESSEXT}" &> /dev/null | |
done | |
# Stuff at the "account" endpoint: | |
for acctthing in following followers blocks muted show favourites; do | |
madonctl accounts ${acctthing} --all | egrep "$FIELDS" > accounts-${acctthing}.0 | |
sleep $SLEEP | |
done | |
# Domain blocks | |
madonctl domain-blocks --show > domain-blocks.0 | |
sleep $SLEEP | |
# Get list of lists | |
madonctl lists show --all > lists.0 | |
# Get membership of each list | |
for list in $(grep 'List ID:' lists.0 | cut -d: -f2); do | |
sleep $SLEEP | |
madonctl lists accounts --list-id $list | egrep "$FIELDS" > list-$list.0 | |
done | |
# Delete any empty lists, except latest | |
find . -size 0 -not -name \*.0 -delete | |
# Compress files or hardlink identical files | |
# If KEEP is high and files don't change often, "hardlink" likely most efficient option | |
case $COMPRESSEXT in | |
.xz) | |
xz *.0 | |
;; | |
.gz) | |
gzip *.0 | |
;; | |
.bz2) | |
bzip2 *.0 | |
;; | |
*) | |
hardlink --ignore-time --keep-oldest --maximize . | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment