Server Running out of space

Emergency clean the server to restore production

On a production without any space, services such as web servers or databases that need to write data or logs can start crashing. A very quick method of restoring the production is removing old system and services logs from /var/log by executing the following command:
sudo find /var/log/ -type f -regex '.*\.[0-9]+\.gz#x27; -delete

Check what is occupying the space

One of the easiest ways to do that is to use the disk usage analyser. Connect to your server via ssh and execute the following command:
cd /; ncdu
This will scan the entire system and check so that you can graphically see what is causing the disk usage.
The most common reasons why the disk is full are the following:
    Service logs that have rotated over a long period of time
    An error is causing a service log to continuously write to the log file
    A service has logs set to DEBUG which is printing too many logs
    Application logs that are taking too much space
    Manual database and application backups
    Too many application versions on the server
    The database or application files are getting too big for the server

Increase Root Disk

The root disk can be increased depending on the cloud, by resizing the instance type or resizing the root disk only. This operation, in most cases, comes with downtime. After you resize the disk it may be required to expand the root filesystem by running this command for ext filesystems:
sudo resize2fs /dev/<device>
and for xfs filesystems:
sudo xfs_growfs <path to mount point>

Add External Disk

If the root disk is getting full the best way is to attach an external disk that can be later on resized without downtime.
    Add and attach an external disk to the existing server from the Bunnyshell Platform.
    Mount the disk in a termporary location
    Move the data from the local storage to the new disk
    Re-mount the disk to the correct location
Last modified 8mo ago