Update PleromaFE Bundle (2.4.0)
[akkoma] / docs / administration / backup.md
1 # Backup/Restore/Move/Remove your instance
2
3 ## Backup
4
5 1. Stop the Pleroma service.
6 2. Go to the working directory of Pleroma (default is `/opt/pleroma`)
7 3. Run `sudo -Hu postgres pg_dump -d <pleroma_db> --format=custom -f </path/to/backup_location/pleroma.pgdump>` (make sure the postgres user has write access to the destination file)
8 4. Copy `pleroma.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 Pleroma service.
10
11 ## Restore/Move
12
13 1. Optionally reinstall Pleroma (either on the same server or on another server if you want to move servers).
14 2. Stop the Pleroma service.
15 3. Go to the working directory of Pleroma (default is `/opt/pleroma`)
16 4. Copy the above mentioned files back to their original position.
17 5. Drop the existing database and user if restoring in-place. `sudo -Hu postgres psql -c 'DROP DATABASE <pleroma_db>;';` `sudo -Hu postgres psql -c 'DROP USER <pleroma_db>;'`
18 6. Restore the database schema and pleroma postgres role the with the original `setup_db.psql` if you have it: `sudo -Hu postgres psql -f config/setup_db.psql`.
19
20 Alternatively, run 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 backup of `config/prod.secret.exs`. Then run the restoration of the pleroma role and schema with of the generated `config/setup_db.psql` as instructed above. You may delete the `config/generated_config.exs` file as it is not needed.
21
22 7. Now restore the Pleroma instance's data into the empty database schema: `sudo -Hu postgres pg_restore -d <pleroma_db> -v -1 </path/to/backup_location/pleroma.pgdump>`
23 8. If you installed a newer Pleroma version, you should run `mix ecto.migrate`[^1]. This task performs database migrations, if there were any.
24 9. Restart the Pleroma service.
25 10. Run `sudo -Hu postgres vacuumdb --all --analyze-in-stages`. This will quickly generate the statistics so that postgres can properly plan queries.
26 11. If setting up on a new server configure Nginx by using the `installation/pleroma.nginx` config sample or reference the Pleroma installation guide for your OS which contains the Nginx configuration instructions.
27
28 [^1]: Prefix with `MIX_ENV=prod` to run it using the production config file.
29
30 ## Remove
31
32 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.
33 * 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.
34 * You can also list local users and delete them individualy using the CLI tasks for [Managing users](./CLI_tasks/user.md).
35 2. Stop the Pleroma service `systemctl stop pleroma`
36 3. Disable pleroma from systemd `systemctl disable pleroma`
37 4. Remove the files and folders you created during installation (see installation guide). This includes the pleroma, nginx and systemd files and folders.
38 5. Reload nginx now that the configuration is removed `systemctl reload nginx`
39 6. Remove the database and database user `sudo -Hu postgres psql -c 'DROP DATABASE <pleroma_db>;';` `sudo -Hu postgres psql -c 'DROP USER <pleroma_db>;'`
40 7. Remove the system user `userdel pleroma`
41 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!