1 # Backup/Restore/Move/Remove your instance
5 1. Stop the Akkoma service.
6 2. Go to the working directory of Akkoma (default is `/opt/akkoma`)
7 3. Run[¹] `sudo -Hu postgres pg_dump -d akkoma --format=custom -f </path/to/backup_location/akkoma.pgdump>` (make sure the postgres user has write access to the destination file)
8 4. Copy `akkoma.pgdump`, `config/prod.secret.exs`[²], `config/setup_db.psql` (if still available) and the `uploads` folder to your backup destination. If you have other modifications, copy those changes too.
9 5. Restart the Akkoma service.
11 [¹]: We assume the database name is "akkoma". If not, you can find the correct name in your config files.
12 [²]: If you've installed using OTP, you need `config/config.exs` instead of `config/prod.secret.exs`.
16 1. Optionally reinstall Akkoma (either on the same server or on another server if you want to move servers).
17 2. Stop the Akkoma service.
18 3. Go to the working directory of Akkoma (default is `/opt/akkoma`)
19 4. Copy the above mentioned files back to their original position.
20 5. Drop the existing database and user if restoring in-place[¹]. `sudo -Hu postgres psql -c 'DROP DATABASE akkoma;';` `sudo -Hu postgres psql -c 'DROP USER akkoma;'`
21 6. Restore the database schema and akkoma role using either of the following options
22 * You can use the original `setup_db.psql` if you have it[²]: `sudo -Hu postgres psql -f config/setup_db.psql`.
23 * Or recreate the database and user yourself (replace the password with the one you find in the config file) `sudo -Hu postgres psql -c "CREATE USER akkoma WITH ENCRYPTED PASSWORD '<database-password-wich-you-can-find-in-your-config-file>'; CREATE DATABASE akkoma OWNER akkoma;"`.
24 7. Now restore the Akkoma instance's data into the empty database schema[¹]: `sudo -Hu postgres pg_restore -d akkoma -v -1 </path/to/backup_location/akkoma.pgdump>`
25 8. If you installed a newer Akkoma version, you should run `MIX_ENV=prod mix ecto.migrate`[³]. This task performs database migrations, if there were any.
26 9. Restart the Akkoma service.
27 10. Run `sudo -Hu postgres vacuumdb --all --analyze-in-stages`. This will quickly generate the statistics so that postgres can properly plan queries.
28 11. If setting up on a new server configure Nginx by using the `installation/akkoma.nginx` config sample or reference the Akkoma installation guide for your OS which contains the Nginx configuration instructions.
30 [¹]: We assume the database name and user are both "akkoma". If not, you can find the correct name in your config files.
31 [²]: You can recreate the `config/setup_db.psql` by running the `mix pleroma.instance gen` task again. You can ignore most of the questions, but make the database user, name, and password the same as found in your backed up config file. This will also create a new `config/generated_config.exs` file which you may delete as it is not needed.
32 [³]: Prefix with `MIX_ENV=prod` to run it using the production config file.
36 1. Optionally you can remove the users of your instance. This will trigger delete requests for their accounts and posts. Note that this is 'best effort' and doesn't mean that all traces of your instance will be gone from the fediverse.
37 * You can do this from the admin-FE where you can select all local users and delete the accounts using the *Moderate multiple users* dropdown.
38 * You can also list local users and delete them individually using the CLI tasks for [Managing users](./CLI_tasks/user.md).
39 2. Stop the Akkoma service `systemctl stop akkoma`
40 3. Disable Akkoma from systemd `systemctl disable akkoma`
41 4. Remove the files and folders you created during installation (see installation guide). This includes the akkoma, nginx and systemd files and folders.
42 5. Reload nginx now that the configuration is removed `systemctl reload nginx`
43 6. Remove the database and database user[¹] `sudo -Hu postgres psql -c 'DROP DATABASE akkoma;';` `sudo -Hu postgres psql -c 'DROP USER akkoma;'`
44 7. Remove the system user `userdel akkoma`
45 8. Remove the dependencies that you don't need anymore (see installation guide). Make sure you don't remove packages that are still needed for other software that you have running!
47 [¹]: We assume the database name and user are both "akkoma". If not, you can find the correct name in your config files.