Backup Mastodon Instance (Docker Version)

This approach makes updating to the latest version a real breeze.

Run docker ps:

docker ps | grep mastodon
8ce5000307c8        tootsuite/mastodon             "/sbin/tini -- bundl…"   2 months ago        Up 10 days          3000/tcp, 4000/tcp                 mastodon_sidekiq_1
3d2814cdaa1f        tootsuite/mastodon             "/sbin/tini -- bundl…"   2 months ago        Up 10 days          0.0.0.0:3000->3000/tcp, 4000/tcp   mastodon_web_1
b877fa74b78e        tootsuite/mastodon             "/sbin/tini -- yarn …"   2 months ago        Up 10 days          3000/tcp, 0.0.0.0:4000->4000/tcp   mastodon_streaming_1
76f93172a5be        postgres:9.6-alpine            "docker-entrypoint.s…"   2 months ago        Up 10 days                                             mastodon_db_1
81e3195075bb        redis:4.0-alpine               "docker-entrypoint.s…"   2 months ago        Up 10 days                                             mastodon_redis_1

Save the current versions using the hashes:

docker commit -p 8ce5000307c8 mastodon_sidekiq_bak_$(date +%Y%m%d%H%M)_1
docker commit -p 3d2814cdaa1f mastodon_web_bak_$(date +%Y%m%d%H%M)_1
docker commit -p b877fa74b78e mastodon_streaming_bak_$(date +%Y%m%d%H%M)_1
docker commit -p 76f93172a5be mastodon_db_bak_$(date +%Y%m%d%H%M)_1
docker commit -p 81e3195075bb mastodon_redis_bak_$(date +%Y%m%d%H%M)_1

Show the saved images:

docker images | grep -E "mastodon_.*?_bak_"
mastodon_redis_bak_201806031351_1       latest              e29f976243cd        23 minutes ago      27.1MB
mastodon_db_bak_201806031351_1          latest              ce277f04a106        23 minutes ago      37.9MB
mastodon_streaming_bak_201806031350_1   latest              f82660395f5a        23 minutes ago      1.35GB
mastodon_web_bak_201806031350_1         latest              b0353e958e0a        24 minutes ago      1.35GB
mastodon_sidekiq_bak_201806031349_1     latest              b981eeea1076        24 minutes ago      1.35GB

Saved images to tarball files:

docker save -o ~/mastodon_redis_bak_201806031351_1.tar mastodon_redis_bak_201806031351_1
docker save -o ~/mastodon_db_bak_201806031351_1.tar mastodon_db_bak_201806031351_1
docker save -o ~/mastodon_streaming_bak_201806031350_1.tar mastodon_streaming_bak_201806031350_1
docker save -o ~/mastodon_web_bak_201806031350_1.tar mastodon_web_bak_201806031350_1
docker save -o ~/mastodon_sidekiq_bak_201806031349_1.tar mastodon_sidekiq_bak_201806031349_1