ITSquad/Mastodon/Maintenance: Difference between revisions
m (→How to backup?) |
|||
Line 53: | Line 53: | ||
It can be interesting to execute the following command before doing a backup: | It can be interesting to execute the following command before doing a backup: | ||
docker-compose run --rm web rails mastodon:media:remove_remote | docker-compose run --rm web rails mastodon:media:remove_remote | ||
This will remove local cache of media older than NUM_DAYS (=7 by default, but we can change this value). | This will remove local cache of media older than NUM_DAYS (=7 by default, but we can change this value). Note that this command is executed every day. | ||
'''Currently, we do not provide automatic backups!''' | '''Currently, we do not provide automatic backups!''' |
Revision as of 00:05, 8 January 2018
This page aims to describe procedures to maintain the Pirate Party's Mastodon instance.
How to upgrade?
A script called update.sh located in /home/mastodon/mastodon will reproduce the steps below. Note: this script stops at step 14 and does not go further.
Before running this script or the following commands, please check the instruction for the current release. Sometimes, aditionnal actions are needed (other than migrate database and compile assets)
- git fetch # update the git branch
- git stash # prevent changes made to the files to be overwritten (mainly, the docker-compose.yml file)
- git checkout vX.X.X # jump to the version where we want to update
- git stash pop # restore your changes
- sed s/v[:digit:].[:digit:].[:digit:]/vX.X.X/g docker-compose.yml # and change vX.X.X by the new version
- docker-compose pull # pull from the docker-hub https://hub.docker.com/r/gargron/mastodon/
- docker-compose stop # stop the containers
- docker start mastodon_db_1 # start the db container
- docker exec -t mastodon_db_1 pg_dumpall -c -U postgres > ../dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql # backup the database
- tail ../your_dump_file.sql # check if the backup worked, with your_dump_file.sql being the dumpfile you have created in the previous step.
- docker-compose down # shut down the containers.
- You'll maybe get "ERROR: An HTTP request took too long to complete" and other errors. Don't mind this and just wait 'till it's done.
- docker-compose run --rm web rails db:migrate # upgrade the database
- docker-compose run --rm web rails assets:precompile # complie the assets
- docker-compose up -d # start the mastodon instance (create new volumes)
- docker-compose logs -ft web # (optional) if you want to monitor the progress. Once this is done you ctrl+c
- docker volume prune # remove all unused volumes
What to do when something went wrong?
Don't panic. You can restore the database backup as follows:
- docker-compose stop
- docker container start mastodon_db_1
- docker exec -t mastodon_db_1 dropdb postgres -U postgres # remove the db !!!!!!!
- docker exec -t mastodon_db_1 createdb postgres -U postgres # create a fresh and new db
- cat ../your_dump_file.sql | docker exec -i mastodon_db_1 psql -U postgres # restore the database, with "your_dump_file" being a database backup
- docker-compose down
- docker-compose up -d
You can also go to a previous version of Mastodon with:
- git checkout vX.X.X
- sed s/v[:digit:].[:digit:].[:digit:]/vX.X.X/g docker-compose.yml
- docker-compose pull
How to backup?
Backups of the database are not enough. We need to backup images, user feeds, etc.
We can simply copy the whole Mastodon's directory. For instance:
tar cvf /home/mastodon/backup/mastodon.tar /home/mastodon/mastodon/
Then, we backup the database:
docker exec -t mastodon_db_1 pg_dumpall -c -U postgres > /home/mastodon/backup/db/dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
It can be interesting to execute the following command before doing a backup:
docker-compose run --rm web rails mastodon:media:remove_remote
This will remove local cache of media older than NUM_DAYS (=7 by default, but we can change this value). Note that this command is executed every day.
Currently, we do not provide automatic backups!