mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.git
synced 2024-10-31 22:17:36 +00:00
135 lines
4.2 KiB
Markdown
135 lines
4.2 KiB
Markdown
---
|
|
title: "How to manually clean up your server's disk space"
|
|
linkTitle: "Manual space cleanup"
|
|
weight: 2
|
|
date: 2023-03-14
|
|
description: >
|
|
Manual cleanup might be required if you need more space on system volume.
|
|
categories: ["How-To Guides"]
|
|
---
|
|
|
|
|
|
{{% pageinfo color="warning" %}}
|
|
All commands in this guide are executed as root over SSH.
|
|
If you do not have root access, see [this guide](/docs/how-to-guides/root_ssh/) for more information.
|
|
|
|
If you have no space left, you will only be able to use the SSH keys you previously added.
|
|
If you run out of disk space and have not added any SSH keys, contact SelfPrivacy support for further assistance.
|
|
{{% /pageinfo %}}
|
|
|
|
There are several ways to clean up your server's disk space.
|
|
|
|
To check how much disk space you have, run the following command:
|
|
|
|
```bash
|
|
df -h
|
|
```
|
|
|
|
This will output a table like this:
|
|
|
|
```
|
|
Filesystem Size Used Avail Use% Mounted on
|
|
devtmpfs 97M 0 97M 0% /dev
|
|
tmpfs 969M 52K 969M 1% /dev/shm
|
|
tmpfs 485M 3.8M 481M 1% /run
|
|
tmpfs 969M 432K 968M 1% /run/wrappers
|
|
/dev/sda1 19G 8.2G 9.5G 47% /
|
|
/dev/sdb 18G 62M 17G 1% /volumes/sdb
|
|
tmpfs 194M 0 194M 0% /run/user/0
|
|
```
|
|
|
|
Here, the filesystem mounted on just `/` is your system volume.
|
|
|
|
## Deleting old NixOS generations
|
|
|
|
{{% alert title="Zero space warning" color="warning" %}}
|
|
This method won't work if you have **no space left** on your system volume. Use other methods first.
|
|
{{% /alert %}}
|
|
|
|
NixOS allows you to roll back to previous system states at any time, at the cost of disk space.
|
|
SelfPrivacy servers are configured to reclaim disk space by automatically deleting old system states,
|
|
but only states older than 7 days are deleted, so you can still use the rollback feature.
|
|
|
|
It is possible to manually delete all old system states, and it may give you more much needed disk space.
|
|
To do this, simply run the following command as root:
|
|
|
|
```bash
|
|
nix-collect-garbage -d
|
|
```
|
|
|
|
This operation might take a while, depending on the number of system states you have.
|
|
When it is done, you will see how much disk space you have freed up.
|
|
|
|
## Deleting old logs
|
|
|
|
Logs sometimes may take up quite a lot of disk space.
|
|
On SelfPrivacy servers, system logs are always limited to 500MiB, but these are not the only
|
|
log files you have on your server.
|
|
|
|
To check how much disk space logs take up, run the following command:
|
|
|
|
```bash
|
|
du -h --max-depth=1 /var/log
|
|
```
|
|
|
|
The output will look something like this:
|
|
|
|
```
|
|
4.0K /var/log/private
|
|
14M /var/log/nginx
|
|
499M /var/log/journal
|
|
587M /var/log
|
|
```
|
|
|
|
### System journal
|
|
|
|
Here, `/var/log/journal` are the system logs where all apps usually write their logs. As you can see in this example,
|
|
they respect the 500MiB limit.
|
|
|
|
If you want to clear *all* system logs, run the following command:
|
|
|
|
```bash
|
|
journalctl --rotate && journalctl --vacuum-time=1s
|
|
```
|
|
|
|
This will usually give you around 450 MiB of free disk space, but not for long.
|
|
This may though be enough to run some commands that will free up more space.
|
|
|
|
### Nginx logs
|
|
|
|
The `/var/log/nginx` directory contains logs for the Nginx web server. If they got too big, you can clear them by running:
|
|
|
|
```bash
|
|
rm /var/log/nginx/* && systemctl reload nginx
|
|
```
|
|
|
|
As you can see, we don't just delete the files, but also reload Nginx.
|
|
This is because Nginx will get confused by the missing log files, and they will not be recreated until Nginx is reloaded.
|
|
|
|
## Deleting old system
|
|
|
|
{{% alert color="warning" %}}
|
|
This operation can only be performed once during the lifetime of your server.
|
|
|
|
If you have installed SelfPrivacy on your own hardware, this may lead to some data loss.
|
|
{{% /alert %}}
|
|
|
|
When you install SelfPrivacy on a server, the existing system gets replaced by NixOS. But the old system is still there
|
|
and takes up disk space, so you can roll back to it if you want.
|
|
|
|
To measure how much disk space the old system takes up, run the following command:
|
|
|
|
```bash
|
|
du -h --max-depth=1 /old-root/
|
|
```
|
|
|
|
If there is no old system in place, you will see `du: cannot access '/old-root/': No such file or directory`.
|
|
|
|
But if you do have an old system, you may delete it by running the following command:
|
|
|
|
```bash
|
|
rm -rf /old-root/
|
|
```
|
|
|
|
This usually frees up around 1.8 GiB of disk space on typical SelfPrivacy servers.
|