Roll back PolarBot
Go back to the version you ran before an update, for example when the new version misbehaves.
Why the database matters
A release may add database migrations. The bot runs them at startup, and an older binary refuses to start on a database that a newer one has migrated (the log then says that a migration was applied that it does not know). So a rollback restores two things together:
- the previous binary,
/opt/polarbot/polarbot.prev(kept by every update), and - the database backup made just before that update,
/var/backups/polarbot/polarbot-<STAMP>.db.
Everything written to the database since that backup (new settings, punishments recorded,
authorizations) is lost. If the update added no migrations (the changelog and
git diff --stat <old commit> <new commit> -- crates/polarbot/migrations tell you), you can
skip the database steps and keep that data.
Steps
Find the backup taken by the update you are undoing (the newest one, usually):
sudo ls -1t /var/backups/polarbot/
Then, with its time stamp in place of <STAMP>:
sudo systemctl stop polarbot
sudo cp -a /opt/polarbot/polarbot.prev /opt/polarbot/polarbot
sudo cp -a /var/backups/polarbot/polarbot-<STAMP>.db /var/lib/private/polarbot/polarbot.db
sudo rm -f /var/lib/private/polarbot/polarbot.db-wal /var/lib/private/polarbot/polarbot.db-shm
sudo cp -a /var/backups/polarbot/polarbot-<STAMP>.db-wal /var/lib/private/polarbot/polarbot.db-wal 2>/dev/null || true
sudo systemctl start polarbot
sudo journalctl -u polarbot -n 30 --no-pager
- The first
cpputs the old binary back;polarbot.prevstays, so you can roll forward again by reinstalling the new build. - The database copy, the removal of the newer write-ahead files and the copy of the backup’s own write-ahead file (if it has one) restore the database exactly as it was before the update.
- The log shows the old version in its first line;
/aboutshows it in Discord.
A rollback posts no update notice. If you restored the database, it no longer remembers that the newer version was announced, so updating to it again posts its notice once more.
Rolling back further
polarbot.prev is only the version before the last update. For anything older, check out that
version in your clone, build it (Update, step 1
with git checkout <commit or tag> instead of stable), install the binary, and restore a
database backup from that time.
If you also changed the unit
If the update installed a new deploy/polarbot.service, install the old one from your clone
(git show <old commit>:deploy/polarbot.service | sudo tee /etc/systemd/system/polarbot.service)
and run sudo systemctl daemon-reload before starting.